I have an xml file from which I wish to parse out certain items
The file has a schema at the top (omitted for brevity) - describing
the structure of the file?. (Please forgive my lack of knowledge but
I'm really just starting out) E.g. it begins
<?xml version="1.0" encoding="utf-8" ?>
<xsd:schema id="root" xmlns=""
Underneath the schema at (the same level of the <xsd:schema> node) are
a number of lines like the following.
Underneath this again (again at the same level) I have what I wish to
parse out e.g.
All I wish to do is to loop through the entire document retrieving the
name of the 'data' node and the values of the associated 'value' and
'comment' nodes. For example
name1, val1 and comment1
name2, val2 and comment2.
I've read a bit about the different ways of parsing XML documents
(e.g. using DOM, XPath etc.) I'm not sure which to use. I don't need
to do any editing just retrieve the values so maybe the XPath will do.
I'd be grateful if somebody could provide an example of how to (1) go
to the first <data> node (2) how to loop through all <data> nodes
getting the values of the <value> and <comment> nodes using either the
DOM or XPath. If this is too much to ask a pointer to any good
examples would really be appreciated.
As an aside is it possible to validate the structure of an XML file
using a schema such as the one mentioned above.