473,386 Members | 1,835 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,386 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 5341


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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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,...

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.