I need to restructure a very large xml source, example is at
http://www.fluffyduck.com.au/sampleXML.xml
I need to modify it for jstree however I’m not sure how to manipulate the data recursively, as loading it as xml with simpleXml only see’s the first 1 user record.
<user id="41" username="bsmain" firstname="Boss" lastname="MyTest" fullname="Test Name" email="lalal@test.com" logins="1964" lastseen="11/09/2012">
</user>
to
<user id="41">
<content><name>bsmain</name></content>
</user>
The problem is some xml lines do not have a closing tag such as , but instead look like this :
<user id="61" username="underling" firstname="Under" lastname="MyTest" fullname="Test Name" email="lalal@test.com" logins="4" lastseen="08/09/2009"/>
If i modify this record and add underling jstree does not recognise it, i’m presuming the /> at the end is the same as ?
I did want to do this in XML but am thinking it may be easier, to simply somehow parse the xml file ‘line by line’, read in the line of data explode it perhaps,
then create a new variable storing it with modified contents such as :
<user id="61">
<content><name>bsmain</name>
</user>
and on the rows where /> exists at the end, manually insert a tag.
there has to be a smarter/faster way to achieve this.
Your best bet is to use
DOMDocumentfor XML parsing. I have written an example that transforms attributes (excluding theidattribute) to content elements:Code
Output