[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Add Node to XmlDocument

Posted on 2004-11-01
6
Medium Priority
?
504 Views
Last Modified: 2008-01-16
Hi

I have the following structure
<Root>
<Person value='10'>
<DetailInfo value='abcd'>

</DetailInfo>
<Addresses>
</Addresses>
</Person>
<Person value='20'>
<DetailInfo value='abcd'>

</DetailInfo>
<Addresses>
</Addresses>
</Person>
<Person value='30'>
<DetailInfo value='abcd'>

</DetailInfo>
<Addresses>
</Addresses>
</Person>
</Root>

I want to add the  Rate and Grade to DetailInfo node based on person value and detail info value and
need to add address node to addresses node based on person value.
<Address>
<State></State>
<City></City>
<Country></Country>
</Address>

If anyone have clue pls help me.
Thanks
Ravi
0
Comment
Question by:pprasadravi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
6 Comments
 
LVL 7

Expert Comment

by:J_Mak
ID: 12469685
Are you using .NET to do this? Please explain your situation. Cheers.
0
 
LVL 6

Expert Comment

by:sathishv
ID: 12469874
If you are using JavaScript,

var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async = false;
xmlDoc.load("test.xml");
personValue = 20;
detailValue = 'abcd';
var detailNode = xmlDoc.selectSingleNode("//DetailInfo[./Person[@value='" + personValue + "'] and ./DetailInfo[@value='" + detailValue + "']]");
var addressNode = detailNode.nextSibling;
var newNode = xmlDoc.createElement("Address");
var newNode2 = xmlDoc.createElement("State"); newNode2.text = "";
var newNode3 = xmlDoc.createElement("City"); newNode3.text = "";
var newNode4 = xmlDoc.createElement("Country"); newNode4.text = "";
newNode.appendChild(newNode2);
newNode.appendChild(newNode3);
newNode.appendChild(newNode4);
addressNode.appendChild(newNode);

The above strip of code selects a DetailInfo tag based on the given person value and detailinfo value, then selects the next sibling of the tag (which is the addresses tag) and appends the newly created elements to it.

Hope this helps.

Cheers,
Sathish
0
 

Author Comment

by:pprasadravi
ID: 12479356
i am sorry we are using asp.net and c#.
0
 
LVL 7

Accepted Solution

by:
J_Mak earned 2000 total points
ID: 12481875
Have a look at this link:

http://samples.gotdotnet.com/quickstart/howto/doc/Xml/WriteXMLFile.aspx

It should help you. Cheers.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question