XMLDocument - Driving me nuts!!

S

Simon Harris

Ok, this really is driving me nuts!!! :(


'All' I am trying to do is get the value of a named element. My XML doc
is:

<?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>

So, I want to get the value of the title element - Should return 'Test'.


Heres my code:

Public Sub LoadFromXML(ByVal strXMLFileLocation As String)
Me.XMLFileLocation = strXMLFileLocation
'Dim XMLFileStream As New FileStream(strXMLFileLocation,
FileMode.Open)
Dim XMLDoc As XmlDocument = New XmlDocument
XMLDoc.Load(strXMLFileLocation)
Dim myXMLNodeList As XmlNodeList =
XMLDoc.GetElementsByTagName("Title")
Me.Title = myXMLNodeList.Item(0).InnerText() <-- This
fails
with error: Object reference not set to an instance of an object.

I've also tried using ...item(1)... - Same error.


Note that this:
Me.Title = myXMLNodeList.Count.ToString
Returns a value of 1 - So I guess the XML document is found and loaded
correctly.


Any help will be appreciated.

Simon.
 

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,968
Messages
2,570,154
Members
46,701
Latest member
XavierQ83

Latest Threads

Top