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.
'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.