Reading xml nodes

C

Christian H

Hello!

I am currently playing around with XmlTextReader and XmlTextWriter.
I've got the TextWriter to write out nodes in this form:

<node>
<childnode>moredata</childnode>

<childnode>moredata</childnode>

<childnode>moredata</childnode>
</node>

What I'having trouble with, is to read these nodes using xmlTextReader.

In all the examples I've seen, the xml format has been different from the
format I've used:

<node someAttribute="data" someOtherAtribute="moredata">
<childnode someAttribute="data" someOtherAtribute="moredata"/>
<childnode someAttribute="data" someOtherAtribute="moredata"/>
</node>

So , I have 2 questions:
-Does anyone have an example on how to read the xmlformat I've used?
-Is this a correct / incorrect xml data format?

Also, If an attribute or a node's data contains " or ', will this mess up
the xmlReader?
Example: <childnode someAttribute="She didn't do it">

Regards Christian H.
 
R

Razzie

How I would read this is:

Put the xml in an XmlDocument
Select all the childnodes using:

XmlNodelist nodeList = xmlDoc.SelectNodes("//node/childnode");
foreach(XmlNode xmlNode in nodeList)
{
// use xmlNode.InnerText to get the moredata
}


And yes your xml data is correct.
Xml data can never contain " or ' as far as I know, you always need to use
special codes for that. For example, <node>A & B</node> is not valid, the
right notation would be <node>A &amp; B</node>
I'm sure the same goes for " and '

Good luck,

Razzie
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top