2 Replies Latest reply on May 19, 2005 4:32 PM by Tim Fessenden

    Parsing a portion of an XML file for use as an extended object

      I've got a large XML file and I want to retrieve bits and pieces of data from it to display in an extended object (probably using the name=value grammar). I do not want to use the entire XML file because it has a lot more data than is necessary. Has anyone figured out a good way to parse XML from within an NSH script, perhaps using some sort of 3rd party binary? Doing it via shell would be possible, but extremely painful I would imagine.

        • 1. Re: Parsing a portion of an XML file for use as an extended object


          You might consider looking for a command line XSLT engine and then defining XSL to generate a reduced, custom XML file.


          I have one but it requires that Java be installed. If you were running centrally, then it would be no problem because the app server has a JRE installed. However, that would mean you would need to copy the file to the app server so it could be read in by the Java utility.


          There are probably other command line utilities out there though that would be stand-alone. In any event, you would also need to learn a bit of XSL. This site is great for that:




          Here is a simple example though. Suppose buried in your XML there were elements named 'foo' and they had child elements named 'param' and 'value'. And suppose the 'foo' element was found at /doc-element/element1/element2/foo


          Then using the following XSL:


          <?xml version="1.0" encoding="UTF-8" ?>
          <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
          <xsl:output method="xml" version="4.0" encoding="UTF-8"></xsl:output>
          <xsl:template match="/">


          <xsl:for-each select="doc-element/element1/element2/foo">
          <xsl:value-of select="param"></xsl:value-of>
          <xsl:value-of select="value"></xsl:value-of>




          would produce output like this:

          <?xml version="1.0" encoding="UTF-8" ?>


          where name1,name2,name3 and value1,value2,value3 are the values of the param-name and param-value elements respectively.



          Anyway, this may be more work than it is worth in your case, but I thought I would put it out there...

          • 2. Re: Parsing a portion of an XML file for use as an extended object

            Thanks for the info. There seems to be a number of command-line XSLT programs out there, but I haven't done the research yet to determine if any are cross-platform. I did find a command line XML tool called XMLStarlet (http://xmlstar.sourceforge.net/) that is pretty nifty for parsing XML files. Assuming the XML tree you're trying to walk isn't too overly complex, you can string together a bunch of these command line calls to pull out just the things you want from the XML file and then display it in a much cleaner format within an extended object.


            NOTE: It doesn't support much in the way of regex or wildcards, so if you're trying to iterate through a bunch of similarly named siblings such as "prop1", "prop2", etc (like I am), you'll have to use XSLT to normalize the data before parsing it.