473,226 Members | 1,319 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,226 software developers and data experts.

insert xml element in a speicific location

let's say i have a xml file

<root>
<stuff id='1'>
<stuff1>
</stuff1>
</stuff>
</root>

how do i insert new <stuff2>element and atrribute after stuff1
Jun 26 '06 #1
3 5334


dotnetnoob wrote:
let's say i have a xml file

<root>
<stuff id='1'>
<stuff1>
</stuff1>
</stuff>
</root>

how do i insert new <stuff2>element and atrribute after stuff1


You can do that with the DOM e.g. (C#)
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.Load(@"file.xml");
xmlElement stuff =
xmlDocument.SelectSingleNode("root/stuff[@id = '1']") as XmlElement;
if (xmlElement != null) {
XmlElement stuff2 = xmlDocument.CreateElement("stuff2");
stuff.AppendChild(stuff2);
}
xmlDocument.Save(@"file.xml");
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Jun 26 '06 #2
hi, thank you for your help but it didn't added to where i want it to be here
is a fragment of xml file that i'm working on

<EventEnrollment InstanceNumber="3747">
<BackwardReferences/>
<EventEnrollmentProperties AckRequired="0" EventEnable="0" EventType="0"
NotifyClass="0" NotifyType="0" PresentValue="0" ToFaultText=""
ToNormalText="" ToOffNormalText="">
<EnabledReference ObjectKey="" PropertyName=""/>
<EventParameters BitMask="0" Deadband="" HighDiffLimit="" HighLimit=""
ListOfBitStringValues="" ListOfValues="" LowDiffLimit="" LowLimit=""
ReferencedPropertyIncrement="1" TimeDelay="60" TimeInterval="1">
<SetpointReference ObjectKey="" PropertyName=""/>
</EventParameters>
<EventSources/>
</EventEnrollmentProperties>
<GeneralProperties Attr="0" InstanceNumber="3747" IsConfigured="0"
ObjectName="test" ObjectType="9" SchemaVer="1.4" TraceOptions="0">
<Description/>
</GeneralProperties>
<EventEnrollment InstanceNumber="9000"/>
</EventEnrollment>
i'll like to create a new EventEnrollment block right after the last
EventEnrollment. how did it got appened into the last EventEnrollment and not
by itself.

"Martin Honnen" wrote:


dotnetnoob wrote:
let's say i have a xml file

<root>
<stuff id='1'>
<stuff1>
</stuff1>
</stuff>
</root>

how do i insert new <stuff2>element and atrribute after stuff1


You can do that with the DOM e.g. (C#)
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.Load(@"file.xml");
xmlElement stuff =
xmlDocument.SelectSingleNode("root/stuff[@id = '1']") as XmlElement;
if (xmlElement != null) {
XmlElement stuff2 = xmlDocument.CreateElement("stuff2");
stuff.AppendChild(stuff2);
}
xmlDocument.Save(@"file.xml");
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/

Jun 26 '06 #3
nevermind, i got it

thank

"dotnetnoob" wrote:
let's say i have a xml file

<root>
<stuff id='1'>
<stuff1>
</stuff1>
</stuff>
</root>

how do i insert new <stuff2>element and atrribute after stuff1

Jun 26 '06 #4

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

Similar topics

12
by: who be dat? | last post by:
I'm trying to make a webpage do the following: I want a user to be able to click on a given image (there will be more than one image). Upon clicking a given image, characters specific to that...
4
by: mike | last post by:
Hello. Let's say I have the following XML document: <ROOT><Element1>Some Text</Element1></ROOT> I want to add a new element after Element1. I tried the following but, naturally, it doesn't...
1
by: Abareblue | last post by:
I have no clue on how to insert a record into access. here is the whole thing using System; using System.Drawing; using System.Collections; using System.ComponentModel;
5
by: Andrew | last post by:
Hi, friends, In ASP, we use obj = CreateObject("com.dll") obj.GetHTMLText(inVal, outHTMLTxt1, outHTMLTxt2) to get different HTML strings based on input values. Then, we insert them into...
4
by: Nick Keighley | last post by:
Hi, I've checked out various documentation for multimap but can't find anywhere it explicitly stated that insert() invalidates multimap iterators. consider this pseudo code:- int...
5
by: asdf | last post by:
I have a program that reads sorted data from a database and inserts it element by element into a set. If the data is sorted is there a faster way to insert ? Meaning is there a way to tell the...
2
by: mirandacascade | last post by:
O/S: Win2K Vsn of Python: 2.4 Example: <a> <b createAnotherWhenCondition="x"> <c>text for c</c> <d>text for d</d> </b>
6
by: flash | last post by:
write a program that manipulates arrays of integers. The main program should call three functions: Insert, Delete, and Search. The Insert function should call a function Sort that sorts the array. ...
4
by: Tim Slattery | last post by:
It would be convenient for my app to store the stuff I'm generating in a std::list. I'd like to remember the location of a particular place in the list - sort of like sticking my finger into it -...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

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.