Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > General .NET
|
General .NET For general discussion of MICROSOFT .NET topics that don't fall within any of the other .NET forum subcategories or .NET language forums.  If your question is specific to a language (C# or Visual Basic) or type of application (Windows Forms or ASP.Net) try an applicable forum category. ** PLEASE BE SPECIFIC WITH YOUR QUESTION ** When posting here, provide details regarding the Microsoft .NET language you are using and/or what type of application (Windows/Web Forms, etc) you are working in, if applicable to the question. This will help others answer the question without having to ask.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the General .NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 18th, 2004, 07:25 AM
Authorized User
 
Join Date: Mar 2004
Posts: 61
Thanks: 0
Thanked 0 Times in 0 Posts
Default Can a XML doc be updated on a Web Form

I have written an XML document out from a process which has some quantity values in an element. A Web Form will decrement these quantity values. Is there some way of updating the XML document rather than having to read and rewrite the whole document out each time a user causes the values to be decremented. Since I am decrementing, there will be no chnage to the physical length of the XML element.



Kerry O'Carroll
Interphase Systems P/L
kerry@interphase.net.au
__________________
Kerry O\'Carroll
 
Old August 18th, 2004, 06:09 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

If you change the file, how else could you possibly save the changes apart from reading the entire file, changing it and then writing it back out. I suppose you could write something that changed the character at a particular byte address on the storage device, but this would seem to me to be more work than it's worth.

Particularly with XML, it should be fairly simple to just open the document in an XML document object, change the node in question, then save the document back to disk. Did you have something else in mind?
 
Old August 18th, 2004, 07:15 PM
Authorized User
 
Join Date: Mar 2004
Posts: 61
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the advice. I will look at changing the way you suggested.

I am just learning XML so any advice is greaterly appreciated.

Thanks again

Kerry O'Carroll
Interphase Systems P/L
kerry@interphase.net.au
 
Old October 4th, 2004, 07:28 PM
Authorized User
 
Join Date: Mar 2004
Posts: 61
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Peter,

What is the best way to change the Node and write it back.

Thanks

Kerry O'Carroll
 
Old October 4th, 2004, 10:54 PM
Authorized User
 
Join Date: Mar 2004
Posts: 61
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I should add, that I am having trouble using the XmlLoad

        Dim xmlDoc As New XmlDocument

        xmlDoc.LoadXml(Server.MapPath(".") & "\available.xml")

When I run the above I get an error. If I code the XML data into a string it works. If I read the data into the string, it strips off all the special xml codes and entities etc. just leave the data.

How do I load an XML file into a DOM so I can update it.

I am using ASP .NET with VB

Kerry O'Carroll
 
Old October 5th, 2004, 11:41 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Can you provide details on the error you are getting? That looks right to me.
 
Old October 5th, 2004, 05:07 PM
Authorized User
 
Join Date: Mar 2004
Posts: 61
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Peter,

Following is the error mesage:


Server Error in '/WebReservation' Application.
--------------------------------------------------------------------------------

The data at the root level is invalid. Line 1, position 1.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Xml.XmlException: The data at the root level is invalid. Line 1, position 1.

Source Error:


Line 631:
Line 632: ' This is where I get the error
Line 633: xmlDoc.LoadXml(strData)
Line 634:
Line 635:


Source File: c:\inetpub\wwwroot\WebReservation\WebReservation.a spx.vb Line: 633

Stack Trace:


[XmlException: The data at the root level is invalid. Line 1, position 1.]
   System.Xml.XmlTextReader.ParseRoot() +295
   System.Xml.XmlTextReader.Read() +127
   System.Xml.XmlValidatingReader.ReadWithCollectText Token()
   System.Xml.XmlValidatingReader.Read()
   System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace) +80
   System.Xml.XmlDocument.Load(XmlReader reader) +72
   System.Xml.XmlDocument.LoadXml(String xml)
   WebReservation.WebReservation.Update_Available() in c:\inetpub\wwwroot\WebReservation\WebReservation.a spx.vb:633
   WebReservation.WebReservation.btnAccept_Click(Obje ct sender, EventArgs e) in c:\inetpub\wwwroot\WebReservation\WebReservation.a spx.vb:210
   System.Web.UI.WebControls.Button.OnClick(EventArgs e)
   System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String eventArgument)
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument)
   System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData)
   System.Web.UI.Page.ProcessRequestMain()




--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:1.1.4322.2032; ASP.NET Version:1.1.4322.2032

Kerry O'Carroll
 
Old October 5th, 2004, 06:43 PM
Authorized User
 
Join Date: Mar 2004
Posts: 61
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

Problem with LoadXml solved.

When loading from a file, use .Load not .LoadXml


Kerry O'Carroll
 
Old October 6th, 2004, 06:06 AM
Authorized User
 
Join Date: Mar 2004
Posts: 61
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

I have another problem when I save the the XML file using the following instructions:

        Dim xmlDoc As New XmlDocument
        Dim availNodes As XmlNodeList
        Dim availNode As XmlNode

        xmlDoc.Load(Server.MapPath(".") & "\release_available.xml")
        ...........
        xmlDoc.Save(Server.MapPath(".") & "\release_available.xml")

How can I re-save this file after I update it. There should be no other processes using this file.

HERE IS THE ERROR MESSAGE


The process cannot access the file "c:\inetpub\wwwroot\WebReservation\release_availab le.xml" because it is being used by another process.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.IO.IOException: The process cannot access the file "c:\inetpub\wwwroot\WebReservation\release_availab le.xml" because it is being used by another process.

Source Error:


Line 590:
Line 591:
Line 592: xmlDoc.Save(Server.MapPath(".") & "\release_available.xml")
Line 593:
Line 594: End Sub





Kerry O'Carroll
 
Old October 10th, 2004, 05:11 PM
Authorized User
 
Join Date: Mar 2004
Posts: 61
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have solved my problem with XmlDoc.Save. The file was being protected from overwritting by the fact it was still open in my program (logic problem).

I will now focus on updating the Nodes.

Thanks for all your help.

Regards

Kerry O'Carroll





Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating XML doc ; writing string(xml format) into KamalRaturi XML 5 May 28th, 2008 05:51 AM
Help making a doc using XML topshed XML 2 January 28th, 2006 08:05 PM
XML code in flash not geting updated sania XSLT 1 January 11th, 2006 01:38 PM
Excel doc on web server rbmohr Classic ASP Components 3 May 11th, 2005 11:52 AM
whole database to XML doc beyondforsaken VB How-To 4 June 11th, 2003 08:12 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.