473,396 Members | 1,975 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Updating an XML Document

63
Hi everyone,

I'm trying to update an XML File using Asp.Net.

I have tried many methods but I dont get file updated.

Can anyone suggest me some method to update an xmlFile?

The last method I tried I have given below.
Apr 30 '07 #1
3 2349
TRScheel
638 Expert 512MB
Hi everyone,

I'm trying to update an XML File using Asp.Net.

I have tried many methods but I dont get file updated.

Can anyone suggest me some method to update an xmlFile?

The last method I tried I have given below.

Your method wasnt posted, but you could use System.XML for it. In addition, you might want to make sure your web server allows you to write with the user you are using.
Apr 30 '07 #2
Paulson
63
Your method wasnt posted, but you could use System.XML for it. In addition, you might want to make sure your web server allows you to write with the user you are using.

Thanks for your advice it helped I used this method to update.Can you say if there is anything wrong in it(It works fine but still any
problem in code ?).

My Xml File
__________________________________________________ ________________


<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="Employee.xsl" ?>
<Employee_details>
<Employee id="1">
<Employee_Name>Anderson</Employee_Name>
<Employee_JobId>250</Employee_JobId>
<Employee_JoiningDate>1/15/2007(January 15 2007)</Employee_JoiningDate>
<Employee_Jobsection>Accounts</Employee_Jobsection>
</Employee>
<Employee id="2">
<Employee_Name>
Krishna
</Employee_Name>
<Employee_JobId>
255
</Employee_JobId>
<Employee_JoiningDate>
1/5/2007(January 5 2007)
</Employee_JoiningDate>
<Employee_Jobsection>
Accounts
</Employee_Jobsection>
</Employee>
<Employee id="3">
<Employee_Name>John</Employee_Name>
<Employee_JobId>260</Employee_JobId>
<Employee_JoiningDate>2/5/2007(February 5 2007)</Employee_JoiningDate>
<Employee_Jobsection>Maintainence</Employee_Jobsection>
</Employee>
<Employee id="4">
<Employee_Name>
Siddharth
</Employee_Name>
<Employee_JobId>
265
</Employee_JobId>
<Employee_JoiningDate>
2/8/2007(February 8 2007)
</Employee_JoiningDate>
<Employee_Jobsection>
Software
</Employee_Jobsection>
</Employee>
<Employee id="5">
<Employee_Name>Ethen</Employee_Name>
<Employee_JobId>270</Employee_JobId>
<Employee_JoiningDate>1/1/2007(January 1 2007)</Employee_JoiningDate>
<Employee_Jobsection>Finance</Employee_Jobsection>
</Employee>
</Employee_details>

__________________________________________________ ________________

And Update Code Part is as follows

__________________________________________________ ________________

If btnUpdate.Text = "Save" Then
AddNewNode()
End If
Dim xDoc As New XmlDocument
Dim rootElement As XmlElement
Dim xElement As XmlElement
Dim xElementValue As XmlElement
Dim count As Integer
Dim xmlId As String = Session("xmlIdVal")
xDoc.Load(Server.MapPath("Employee.xml"))
rootElement = xDoc.DocumentElement
xElement = rootElement.FirstChild
Dim elementCount As Integer = rootElement.ChildNodes.Count

For count = 0 To elementCount
If xElement.GetAttribute("id") <> xmlId Then
xElement = xElement.NextSibling
Else
count = elementCount
End If
Next

'Assign the values in the textboxes
'Update the elements using Innertext & InnerXml
'Updating first element-->
'EmployeeName
xElementValue = xElement.Item("Employee_Name")
xElementValue.InnerText = txtEmployeeName.Text
xElementValue.InnerXml = txtEmployeeName.Text
'JoiningDate
xElementValue = xElement.Item("Employee_JoiningDate")
xElementValue.InnerText = txtJoiningDate.Text
xElementValue.InnerXml = txtJoiningDate.Text
'JobId
xElementValue = xElement.Item("Employee_JobId")
xElementValue.InnerText = txtJobId.Text
xElementValue.InnerXml = txtJobId.Text
'Jobsection
xElementValue = xElement.Item("Employee_Jobsection")
xElementValue.InnerText = txtJObSection.Text
xElementValue.InnerXml = txtJObSection.Text

'Save the xml-File in reqd loaction
Dim XmlFilePathLocation As String
XmlFilePathLocation = Request.PhysicalApplicationPath
xDoc.Save(XmlFilePathLocation + "Employee.xml")

'Show the Updated XmlFile Values
Response.Redirect("Employee.xml")

__________________________________________________ ________________


Pls check and tell me if there is some prob. I am using Vb.Net

Thanks in advance -- bye Paulson
May 3 '07 #3
TRScheel
638 Expert 512MB
Thanks for your advice it helped I used this method to update.Can you say if there is anything wrong in it(It works fine but still any
problem in code ?).

...
everything looks fine, but you are copy/pasting a lot of code. It would do you good to do some refactoring.

Here is some code I wrote for our business library where I work for xml. it might help you out (its in c#, so hopefully it reads well... if you have issues understanding it, just tell me and I will convert it into VB)


Expand|Select|Wrap|Line Numbers
  1. public static XmlElement CreateElement(XmlDocument xmlDocument, string elementName, string innerText, XmlElement xmlParent)
  2.             {
  3.                 XmlElement XmlElement = xmlDocument.CreateElement(elementName);
  4.                 if (innerText != null && xmlParent != null)
  5.                 {
  6.                     XmlElement.InnerText = innerText;
  7.                     xmlParent.AppendChild(XmlElement);
  8.                 }
  9.                 return XmlElement;
  10.             }
  11.  
  12.             public static void CreateDeclaration(XmlDocument xmlDocument)
  13.             {
  14.                 XmlDeclaration AccessRequestDeclaration = xmlDocument.CreateXmlDeclaration("1.0", null, null);
  15.                 xmlDocument.AppendChild(AccessRequestDeclaration);
  16.             }
Some clarifications, the declaration can be changed as needed, and it is always ran first in a document. The create element is then called for each subsequent element. You could even refactor further, depending on your application.
May 10 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Jason | last post by:
Let's say I have an html form with 20 or 30 fields in it. The form submits the fields via POST to a php page which updates a table in a database with the $_POST vars. Which makes more sense? ...
1
by: Tommy | last post by:
Hi, I have 3 frames. One to let the user input a URL, one to display the page of that URL and one to display some info on that page (including all the links of the page). The problem is that...
2
by: m | last post by:
hi all, got an interesting problem: im working with purchase orders and in detail line i have a date field. so for example: header line: PO code: X123 PO value: ...
3
by: Jim Cobban | last post by:
I have a set of web pages that are organized in pairs. One of each pair contains a graphic and the other is an extended description of the graphic. I am trying to set it up that selecting a single...
14
by: el_sid | last post by:
Our developers have experienced a problem with updating Web References in Visual Studio.NET 2003. Normally, when a web service class (.asmx) is created, updating the Web Reference will...
2
by: Rob Long | last post by:
Hi I have an HTML select element in my page and it's multiple property is disabled (one item at a time mode) but I still want to transfer all the items in the select to the server when the form...
15
by: webstormcomputers | last post by:
I'm trying to update a hidden field with java script and I'm only getting one of the values from my select stament. Here is the code below. <select name="on0"> <option value="25">25 <option...
1
by: mrtm3050 | last post by:
I want to try to update a pre-existing html page by adding a certain tag <option> within a <select> tag. The code used below: function showDuplicate() { if (!newWin || newWin.closed){ newWin...
5
by: rosaryshop | last post by:
I'm working a jewelry/rosary design web site at http://www.rosaryshop.com/rosariesAndKits2.php. As the user makes selections, it updates images of various parts, giving them a preview of the...
2
by: =?Utf-8?B?TUNN?= | last post by:
I have an asp.net page that contains an update panel. Within the update panel, controls get added dynamically. During partial page post backs the controls within the panel will change. I have a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...

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.