473,657 Members | 2,537 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Updating contents of XML node

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(H ttpContext.Curr ent.Server.MapP ath(strXMLFileL ocation))
loNode = loXMLDoc.Select SingleNode("/Site/Content/TextArea" &
textAreaID)
loNode.InnerTex t = strContent
loXMLDoc.Save(H ttpContext.Curr ent.Server.MapP ath(strXMLFileL ocation))
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(H ttpContext.Curr ent.Server.MapP ath(strXMLFileL ocation))
loXMLDoc.Load(o bjStreamReader)
loNode = loXMLDoc.Select SingleNode("/Site/Content/TextArea" &
textAreaID)
loNode.InnerTex t = strContent
objStreamReader .Close()
objStreamReader = Nothing
loXMLDoc.Save(H ttpContext.Curr ent.Server.MapP ath(strXMLFileL ocation))
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.

Nov 19 '05 #1
4 1445
Change back to your origional code, and do this before running:

- Open your XML file in Notepad
- Make sure your first line looks like this:
<?xml version="1.0" encoding="utf-8"?>
- Go to Save As...
- Change the Encoding option to UTF-8 and click save to save it.

Hope that helps.

"Web Team @ Borough of Poole" wrote:
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(H ttpContext.Curr ent.Server.MapP ath(strXMLFileL ocation))
loNode = loXMLDoc.Select SingleNode("/Site/Content/TextArea" &
textAreaID)
loNode.InnerTex t = strContent
loXMLDoc.Save(H ttpContext.Curr ent.Server.MapP ath(strXMLFileL ocation))
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(H ttpContext.Curr ent.Server.MapP ath(strXMLFileL ocation))
loXMLDoc.Load(o bjStreamReader)
loNode = loXMLDoc.Select SingleNode("/Site/Content/TextArea" &
textAreaID)
loNode.InnerTex t = strContent
objStreamReader .Close()
objStreamReader = Nothing
loXMLDoc.Save(H ttpContext.Curr ent.Server.MapP ath(strXMLFileL ocation))
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.

Nov 19 '05 #2
Hi Andy,

Thanks for your post, I did as you said with the XML file, and my code
now reads:

Dim loXMLDoc As XmlDocument = New XmlDocument
Dim loNode As XmlNode

loXMLDoc.Load(H ttpContext.Curr ent.Server.MapP ath(strXMLFileL ocation))
loNode = loXMLDoc.Select SingleNode("/Site/Content/TextArea"
& textAreaID)
loNode.InnerTex t = strContent

loXMLDoc.Save(H ttpContext.Curr ent.Server.MapP ath(strXMLFileL ocation))
loNode = Nothing
loXMLDoc = Nothing

Looks like we've solved the UTF8 error :) But I am still getting this
one, which I assumed was due to using the streamreader, but perhaps
not?

"The process cannot access the file "<Path to my XML doc>" because it
is being used by another process"

Any more help anyone may be able to offer will be appreciated.

Regards,

Simon.

Nov 19 '05 #3
I converted your code into my own C# example (b/c I don't really know VB),
and here's what I got:

XmlDocument doc = new XmlDocument();
doc.Load(HttpCo ntext.Current.S erver.MapPath("/TestWebApp/XMLFile1.xml")) ;
XmlNode node = doc.SelectSingl eNode("/ReportDef");
node.InnerText = "hello world";
doc.Save(HttpCo ntext.Current.S erver.MapPath("/TestWebApp/XMLFile1.xml")) ;
node = null;
doc = null;

First, I got an error that I expected: "Access denied". By default, files in
web accessable directories don't have write permission granted to the aspnet
user. After giving "Everyone" full control of this file, the code executed
without error. Do you have the file open in an XML editor also? Maybe it
really is being used by another process?
"Web Team @ Borough of Poole" wrote:
Hi Andy,

Thanks for your post, I did as you said with the XML file, and my code
now reads:

Dim loXMLDoc As XmlDocument = New XmlDocument
Dim loNode As XmlNode

loXMLDoc.Load(H ttpContext.Curr ent.Server.MapP ath(strXMLFileL ocation))
loNode = loXMLDoc.Select SingleNode("/Site/Content/TextArea"
& textAreaID)
loNode.InnerTex t = strContent

loXMLDoc.Save(H ttpContext.Curr ent.Server.MapP ath(strXMLFileL ocation))
loNode = Nothing
loXMLDoc = Nothing

Looks like we've solved the UTF8 error :) But I am still getting this
one, which I assumed was due to using the streamreader, but perhaps
not?

"The process cannot access the file "<Path to my XML doc>" because it
is being used by another process"

Any more help anyone may be able to offer will be appreciated.

Regards,

Simon.

Nov 19 '05 #4
Hi Andy,

I followed your plan and produced a standalone page looking at a
standalone XML file (Not part of the site) and the code works as
expected everytime.

Looks like I need to track down where I am leaving the XML file open.

Thank you very much for your help!

Simon.

Nov 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1871
by: Rostov | last post by:
I've got a script where I'm trying to toggle the visibility of a div node by a click on an image that is the sibling of the div. So I've got this HTML: <div> <img src="RightPointingTriangle.gif" onclick="openclose(this);"> <span class="title">title</span> <div class="contents"> Hi. This is the contents.
3
1876
by: J Krugman | last post by:
This question refers to the DOM. I would like to dynamically append some small amount of text to the all-text content of a <pre> node. I suppose that I could extract the existing content, and replace the <pre> node in question with a new <pre> node that has the extended content. But the existing content is longish, and it seems to me wasteful to rewrite it all just to have a small amount of text tacked on to the end. Is there a way to...
4
2326
by: JoBean | last post by:
I think this is a simple Q but I cannot get the syntax right. I want to specify the node name and get its contents. I do not want to loop through and grab the contents of all child nodes - which the code below is doing fine. I want to replace the inner loop by specifying the node name (name, description) - Everything I try returns an obj ref error. Can someone please point me in the right direction? Many thanks - JoBean 'CODE BEHIND MY...
9
1741
by: Rocky | last post by:
I have 2 textboxes. When I click submit, i want to add whatevers in the text box1 as username and whatevers in textbox2 as userid into an xml file. How do I do that in ASP.NET using vb.net? My xml file look like this: <?xml version="1.0" encoding="utf-8" ?> <!-- format is <user>userid</user> --> <userdata> <user name="Username1"> <userid>abc1</userid>
1
2595
by: Christian Rühl | last post by:
hey! what i wanna do sounds very simple at first, but it turned out to be a real bone crusher... i want to check if a treeView node is checked and if a correspondent node in my xml config file exists just to sort of synchronize them by changing the xml nodes attribute(s). somehow i always catch an exception "blabla has an invalid token" but i cannot find a solution for this. maybe someone of you people can tell me how to do this...
0
2287
by: drop | last post by:
Hi, I'm currently working with the Treeview control in ASP .Net 2.0. The tree is filled dynamically based on data contained in a MySQL Database. Here is the exact behavior I want : 1 - User clicks on a node to expand it. 2 - Add a child node to the node clicked by the user saying the tree is loading that part. So here, I also need to expand the node clicked by
2
17535
by: Pugi! | last post by:
Using AJAX I want to send some information from the server (php-page) as XML to the client. The contents can be very divers so I have to use XML instead of text. On one occasion the contents is html, I can put this in a CDATA section with PHP, but how do I retrieve that information with Javascript and put the HTML in a div ? thanx, Pugi!
1
1944
by: Tedros.G | last post by:
Hi I have an attribute the appears in both the root node and child node for example, below the attribute VERSION appears in the rood node (PRODMSG ) and a child node (OPERATION ) ================ INPUT XML ================ <?xml version="1.0" encoding="utf-16"?> <PRODMSG VERSION="1.2" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
0
1896
by: Falcula | last post by:
Hello, I have a treeview that i fill from a database, when i update nodename in database the treeview dont update. Its works when iam not useing enableviewstate="true" but then i loosing the current selection and stuff in the tree. I post my code here, any idea ?
0
8303
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8821
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8723
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8602
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6162
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4150
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
1941
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1601
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.