Dave's Brain

Browse - programming tips - parse xml

Date: 2008oct6

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

A.

javaScript

	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
	}

PHP

	$xml = simplexml_load_string($txt);
	var_dump($xml);

Perl

	use XML::Simple;
	use Data::Dumper;

	$xml = new XML::Simple;
	$data = $xml->XMLin(txt);
	print Dumper($data);

C/C++
	Expat
	http://expat.sourceforge.net
What this info useful to you? You can donate to say thanks

Add a comment

Sign in to add a comment
Copyright © 2008-2012, 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.
Advertisements: