Sort through all attributes in XML tree with PHP XMLReader -
I have some PHP code to convert an XML file to a CSV file During testing, I did not create a CSV file I am just resonating results in CSV format.
Whenever the XMLReader reaches an empty element, it outputs all the properties of the element.
1) Is there a way to produce a property name with its values (is there any $ xml-> attribute name that goes with $ xml-> value)?
2) What is a way to sort all the properties in the whole tree and not only in the empty element?
& lt ;? Php ini_set ('memory_limit', '50M'); $ X = file_get_contents ('H8_data.xml'); $ Xml = New XMLReader (); $ Xml- & gt; Open ('H8_data.xml', tap, 1 & lt; <19); $ Num = 1; While ($ xml- & gt; read () & amp; amp; $ num & lt; = 2000) {if ($ xml-> EmptyElement) {if ($ xml- & gt; heatluals) {while ( $ Xml- & gt; MoveToNextAttribute ()) {echo $ xml- & gt; Values, ','; }} Echo '& lt; Br / & gt; '; $ Number ++; }}
?>
$ xml-> Returns the name Proper names of nodes Because properties are nodes with XMLReader :: ATTRIBUTE type, the name $ xml-> will return the name of the current attribute in that state. Below is the code version, which outputs both the attribute names and values.
& lt ;? Php ini_set ('memory_limit', '50m '); $ X = file_get_contents ('H8_data.xml'); $ Xml = New XMLReader (); $ Xml- & gt; Open ('H8_data.xml', tap, 1 & lt; <19); $ Num = 1; While ($ xml- & gt; read () & amp; amp; $ num & lt; = 2000) {if ($ xml-> EmptyElement) {if ($ xml- & gt; heatluals) {while ( $ Xml- & gt; MoveToNextAttribute ()) {echo $ xml- & gt; Name, '=', $ xml- & gt; Values, ','; }} Echo '& lt; Br / & gt; '; $ Number ++; }}? & Gt;
Comments
Post a Comment