W
Web Team @ Borough of Poole
Hi All,
I'm trying to update the contents of an XML node. My original code:
Dim loXMLDoc As XmlDocument = New XmlDocument
Dim loNode As XmlNode
loXMLDoc.Load(HttpContext.Current.Server.MapPath(strXMLFileLocation))
loNode = loXMLDoc.SelectSingleNode("/Site/Content/TextArea" &
textAreaID)
loNode.InnerText = strContent
loXMLDoc.Save(HttpContext.Current.Server.MapPath(strXMLFileLocation))
loNode = Nothing
loXMLDoc = Nothing
Causes this error:
"There is no Unicode byte order mark. Cannot switch to Unicode."
I Googled the error and found that a work around is to read the file in
via a streamreader, then open the XML doc from the stream. So, my new
code is:
Dim loXMLDoc As XmlDocument = New XmlDocument
Dim loNode As XmlNode
Dim objStreamReader As StreamReader
objStreamReader =
File.OpenText(HttpContext.Current.Server.MapPath(strXMLFileLocation))
loXMLDoc.Load(objStreamReader)
loNode = loXMLDoc.SelectSingleNode("/Site/Content/TextArea" &
textAreaID)
loNode.InnerText = strContent
objStreamReader.Close()
objStreamReader = Nothing
loXMLDoc.Save(HttpContext.Current.Server.MapPath(strXMLFileLocation))
loNode = Nothing
loXMLDoc = Nothing
Which causes a different error:
"The process cannot access the file "<Physical path to my XML file>"
because it is being used by another process."
Any help/suggestions will be much appreciated!
Thanks,
Simon.
I'm trying to update the contents of an XML node. My original code:
Dim loXMLDoc As XmlDocument = New XmlDocument
Dim loNode As XmlNode
loXMLDoc.Load(HttpContext.Current.Server.MapPath(strXMLFileLocation))
loNode = loXMLDoc.SelectSingleNode("/Site/Content/TextArea" &
textAreaID)
loNode.InnerText = strContent
loXMLDoc.Save(HttpContext.Current.Server.MapPath(strXMLFileLocation))
loNode = Nothing
loXMLDoc = Nothing
Causes this error:
"There is no Unicode byte order mark. Cannot switch to Unicode."
I Googled the error and found that a work around is to read the file in
via a streamreader, then open the XML doc from the stream. So, my new
code is:
Dim loXMLDoc As XmlDocument = New XmlDocument
Dim loNode As XmlNode
Dim objStreamReader As StreamReader
objStreamReader =
File.OpenText(HttpContext.Current.Server.MapPath(strXMLFileLocation))
loXMLDoc.Load(objStreamReader)
loNode = loXMLDoc.SelectSingleNode("/Site/Content/TextArea" &
textAreaID)
loNode.InnerText = strContent
objStreamReader.Close()
objStreamReader = Nothing
loXMLDoc.Save(HttpContext.Current.Server.MapPath(strXMLFileLocation))
loNode = Nothing
loXMLDoc = Nothing
Which causes a different error:
"The process cannot access the file "<Physical path to my XML file>"
because it is being used by another process."
Any help/suggestions will be much appreciated!
Thanks,
Simon.