Xmllint Usage examples 

Options 

--auto Generate a small document for testing purposes.
$ xmllint --auto
<?xml version="1.0"?>
<info>abc</info>
--htmlout
       Output results as an HTML file. This causes xmllint to output
       the necessary HTML tags surrounding the result tree output so
       the results can be displayed/viewed in a browser.
 $ xmllint --auto | xmllint --htmlout -
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
        "http://www.w3.org/TR/REC-html40/loose.dtd">
<html><head><title>xmllint output</title></head>
<body bgcolor="#ffffff"><h1 align="center">xmllint output</h1>
<?xml version="1.0"?>
<info>abc</info>
</body></html>

Xmllint hints 

  1. If you're on a unixy box try using 'xmllint -shell some_xml_file.xml' which will give you a shell to navigate around in the XML file. You can type 'help' for a list of commands but the ones I find most usefull are: cd, dir, ls, cat, pwd. I'm not enough of an expert to figure out what the leading fields on an ls are but I do know that to cd into arrays you use the syntax 'cd array[4]' to get to a particular element. See http://marty.feebleandfrail.org/macosxhints/webscrape/ for a tutorial I wrote on using xmllint and XML::LibXML to scrape web pages.

  2. Run the XML response from smugmug through a trivial parser like http://docs.python.org/lib/expat-example.html. If you're traversing the XML structure, adding calls to something like Perl's Data::Dumper or the Python module pprint to your code is a huge help.

  3. Open the XML file in your browser! Compare the output of (1) and (2) as well as your debug messages.

  4. Some APIs to XML parsers have annoying built in smartness where they automagically change how the data is returned. These can do wierd things to your parsed results! One of the Perl XML parsers, XML::Simple, for example, has a bunch of flags such as ForceArray (http://search.cpan.org/~grantm/XML-Simple-2.12/lib/XML/Simple.pm) and KeyAttr that control how the library will roll single nested elements up into attributes and when it will return arrays vs. hashes. In particular I found that you have to be very aware how XML::Simple behaves when there's one element (a user with 1 album, say) vs. multiple elements.

studiosells

use "xmllint" with XPath 

http://sourceforge.net/mailarchive/forum.php?forum_id=26200&max_rows=25&style=nested&viewmonth=200406

use "xmllint" with an appropriate XPath to find the XML element you want, such as:

@ver = qx(echo "cat
//key[text()="ProductVersion"]/following-sibling::*/text()" | xmllint
--shell /System/Library/CoreServices/SystemVersion.plist);
chomp $ver[1];
return $ver[1];

That way, if the ordering (or number) of keys in the SystemVersion.plist file changes at some point, the command doesn"t break and you can still find the data you want to get out of the file. — It"s not much shorter nor simpler… but it should be more robust.