Dave's Brain

Browse - Programming Tips - How do I parse XML in my favorite language?

Date: 2008oct6

Q.  How do I parse XML in my favorite language?



function parseXMLString(txt) { var obj; if (window.DOMParser) { // Firefox var parser = new DOMParser(); obj = parser.parseFromString(txt,'text/xml'); } else { // IE obj = new ActiveXObject('Microsoft.XMLDOM'); obj.async='false'; obj.loadXML(txt); } return obj; // Both Firefox and IE have different methods for loading files }
$xml = simplexml_load_string($txt); var_dump($xml);
use XML::Simple; use Data::Dumper; $xml = new XML::Simple; $data = $xml->XMLin(txt); print Dumper($data);
Expat http://expat.sourceforge.net

Add a comment

Sign in to add a comment
Copyright © 2008-2018, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.