XMLTextReader

S

Simon Harris

Hi All,

I am trying to set properties of a class from the values of an XML
document.

The document is structured like this:

<?xml version="1.0" encoding="utf-16" standalone="yes" ?>
- <Page>
<Title>Test</Title>
<MetaKeywords>Test</MetaKeywords>
<MetaDescription>Test</MetaDescription>
<Content>Test</Content>
- <Audit>
<LastUpdateBy />
<LastUpdateDate>08/05/2005 09:25:32</LastUpdateDate>
</Audit>
</Page>

The code I have used is:
Me.XMLFileLocation = strXMLFileLocation
Dim XMLFileStream As New FileStream(strXMLFileLocation, FileMode.Open)
Dim XMLReader As New XmlTextReader(XMLFileStream)
XMLReader.MoveToContent()
XMLReader.Read()
XMLReader.Read()
Me.Title = XMLReader.Value
XMLReader.Close()
XMLFileStream.Close()

Note the multiple .read() to skip to the desired element. Obviously this
is
far from elegant, as if any change to the structure of the XML will make
this fail.

What I would really like to do is have my code look for an element by
name,
then assign its value to my properties.

Thanks,

Simon
 
S

Simon Harris

Thanks, I have managed to get the data out like this, but I would like to
get the value of the specific, required element(s).
 

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

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,049
Latest member
Allen00Reed

Latest Threads

Top