fld00d
Member
- Joined
- May 9, 2009
- Messages
- 5
- Programming Experience
- Beginner
Hello,
I am working with an XML file that uses Nodes and Attributes. I have written a function to handle the writing of the XML data to a file:
My code fails on the XmlFileWriter.SelectSingleNode statement. The variable 'nod' always contains nothing, meaning that I am probably not selecting the node/attribute correctly.
I call the function using the following statements:
My XML file format is as follows:
As you might suspect, this XML file is pulled by a webpage and reads the XML data in the VALUE attribute to set the Doc Title and Meta content for it's respective webpage using ASP.Net and VB.Net.
Any help with this would be outstanding, as I know that this is just a limitation of my knowledge with VB.Net and probably a very simple fix that I cannot figure out.
I am working with an XML file that uses Nodes and Attributes. I have written a function to handle the writing of the XML data to a file:
VB.NET:
Public Function WriteXmlData(ByVal StrNodeKeyName As String, ByVal strNodeVal As String, ByRef XmlFileName As String) As String
Dim strMessage As String = ""
Try
Dim XmlFileWriter As New System.Xml.XmlDocument
XmlFileWriter.Load(XmlFileName)
Dim nod As XmlNode = XmlFileWriter.SelectSingleNode("/pageinfo[@key=strNodeKeyName]")
If nod IsNot Nothing Then
nod.Attributes("value").Value = strNodeVal
XmlFileWriter.Save(XmlFileName)
strMessage = "Meta content updated successfully."
Else
strMessage = "Error writing meta content."
End If
Catch ex As Exception
Throw ex
strMessage = "Error writing meta content."
End Try
Return strMessage
End Function
My code fails on the XmlFileWriter.SelectSingleNode statement. The variable 'nod' always contains nothing, meaning that I am probably not selecting the node/attribute correctly.
I call the function using the following statements:
VB.NET:
Dim strMessage1 As String = WriteXmlData("title", strDocTitle, strXmlFileName)
Dim strMessage2 As String = WriteXmlData("description", strDocDescription, strXmlFileName)
Dim strMessage3 As String = WriteXmlData("keywords", strDocKeywords, strXmlFileName)
Dim strMessage4 As String = WriteXmlData("content", strDocContent, strXmlFileName)
My XML file format is as follows:
VB.NET:
<?xml version="1.0" encoding="utf-8"?>
<pageinfo>
<add key="title" value="Some Title" />
<add key="keywords" value="some keywords" />
<add key="content" value="some content words" />
<add key="description" value="a description" />
</pageinfo>
As you might suspect, this XML file is pulled by a webpage and reads the XML data in the VALUE attribute to set the Doc Title and Meta content for it's respective webpage using ASP.Net and VB.Net.
Any help with this would be outstanding, as I know that this is just a limitation of my knowledge with VB.Net and probably a very simple fix that I cannot figure out.