CRXML,A Replacement for SimpleXML

Coding Critique is the place to post source code for peer review by other members of DevNetwork. Any kind of code can be posted. Code posted does not have to be limited to PHP. All members are invited to contribute constructive criticism with the goal of improving the code. Posted code should include some background information about it and what areas you specifically would like help with.

Popular code excerpts may be moved to "Code Snippets" by the moderators.

Moderator: General Moderators

max529
Forum Commoner
Posts: 50
Joined: Sat May 19, 2007 4:10 am

Re: CRXML,A Replacement for SimpleXML

Post by max529 »

Hi,

I have recently moved the class and demo to pagodabox.com which provides better hosting. So the demo and downloads should work faster.

These are the links

Documentation at http://crxml.pagodabox.com

Demo at http://crxml.pagodabox.com/demo.php

Class source ,Documentation and demo http://crxml.pagodabox.com/crXml.tar

I recently had great success with this class with the work I am currently working on. This involved recieving an namespaced xml string, Change some attributes of some nodes and resend it to another server. I could accomplish this with < 10 lines of code.

Below Sample illustrates the operation

Code: Select all

<?php
include 'crXml.php';
$x = new crXml();
$xmlStr = <<<EOB
<?xml version="1.0" encoding="UTF-8"?>
<records>
<person age="15">
<name>
alex
</name>
</person>
<person age="28">
<name>
sandeep
</name>
</person>
</records>
EOB;
$x->loadXML($xmlStr);
$x->records->person[1]['age'] = '30'; //sets second persons attribute to 30
$x->records->person[1]->name = 'albert'; // sets child node 'name' of second person to 'albert'
$x->records->person[2] = $x->records->person[1]; // create a third `person` node and assign it the value of second 'person' node.
echo $x->xml();
Outputs

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<records>
<person age="15">
<name>alex</name>
</person>
<person age="30">
<name>albert</name>
</person>
<person>
<name>albert</name>
</person>
</records> 
Regards,
Sandeep.
max529
Forum Commoner
Posts: 50
Joined: Sat May 19, 2007 4:10 am

Re: CRXML,A Replacement for SimpleXML

Post by max529 »

Hi,

I have added some self guided tutorial like functionality to the demo at http://crxml.pagodabox.com/demo.php so that you can check the capabilities of the class by trying out examples at http://crxml.pagodabox.com...

Regards,
Sandeep.
max529
Forum Commoner
Posts: 50
Joined: Sat May 19, 2007 4:10 am

Re: CRXML,A Replacement for SimpleXML

Post by max529 »

hi..

I have added couple of functionality to the class like the direct node replacement and adding a child xml node to another xml document on the fly using factory method.

regards,
Sandeep
Post Reply