Re: getting the right XML tag in the parse.



..oO(news@xxxxxxxxxxxxxx)

I'm trying to parse an XML formatted post reply, and I can't figure
out how to get the value of the right tag.
The XML is formatted like this:

<A>
<foo>val1</foo>
</A>
<B>
<foo>val2</foo>
</B>
<BAR>
val3
</BAR>

If this is the entire document, then it's not well-formed XML, because
there's no root element.

I need the value of A's "foo", not B's "foo". But from what I can find
I can only get the value of the lowest nested tag in a nest. i.e.:
"foo" or "BAR". Not specifically A or B's "foo".

Of course you can access every element and every attribute in the tree.
Just use the right tools.

Below is the script I'm using. In this case "TOTALCHARGES" is the
"foo" I'm looking for, but I need it to specifically get A's and not
B's.
If someone can point me to where I can find out how, I'd appreciate
it!
[...]

You don't have to write your own parser. Use the SimpleXML extension
with some XPath expressions to get all the nodes you want.

Micha
.



Relevant Pages

  • Re: Editing XML
    ... I wonder how text and child nodes are distinguished in the XML text. ... The first is the processing instruction, which you'll typically ignore in XSLT. ... THe next is the element node named "tag" and the last is the text node. ... There is always exactly one root element in a valid XML document. ...
    (comp.lang.pascal.delphi.misc)
  • Re: Editing XML
    ... THe next is the element node named "tag" and the last is the text node. ... which defines the end of the same element node that <xml> began. ... Most probably it's the implementation of MSXML, where closing tags seem to translate into their own nodes, with the name and type of the opening tag, they only don't have child nodes and attributes. ... There is always exactly one root element in a valid XML document. ...
    (comp.lang.pascal.delphi.misc)
  • Re: appending data to xml file
    ... It's fundamental that an XML document has "closure". ... content in the XML file must be the end tag of this root element. ...
    (comp.text.xml)
  • RE: :Writer beginner problems
    ... A rule of XML is that there MAY ONLY BE ONE ROOT ELEMENT. ... Subject: XML::Writer beginner problems ... Attempt to insert start tag after close of document element at ./test.pl ...
    (perl.beginners)
  • Re: How can I ensure that I always have a list?
    ... tdom is an XML parsing extension for Tcl. ... # Match one tag. ... # quotes, ... # key/value pair) for further processing the next time we go ...
    (comp.lang.tcl)