473,498 Members | 1,704 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XML between two XmlNodes

Hi,
I have two elements in XmlNode objects belonging to one XmlDocument. How
can I get the xml markup between these two?

I mean if the document looks like

<parent>
<child1 />
<child2 />
<child3>
<sub3child />
</child3>
<child4 />
</parent>

So when the first XmlNode will be the child2 element and the second one will
be the child4, I expect to get
<child2 />
<child3>
<sub3child />
</child3>
string. I don't care in/excluding the boundary nodes themselves since I can
correct this using PreviousSibling and NextSibling nodes.

Any simple way to do it? Or anything better/faster than IndexOf in xml
strings does not exist?

Thanks,
Jan

Aug 25 '06 #1
2 984
"Jan Kucera" <ku****@lupacovka.czwrote in message
news:78**********************************@microsof t.com...
Hi,
I have two elements in XmlNode objects belonging to one XmlDocument. How
can I get the xml markup between these two?

I mean if the document looks like

<parent>
<child1 />
<child2 />
<child3>
<sub3child />
</child3>
<child4 />
</parent>

So when the first XmlNode will be the child2 element and the second one
will be the child4, I expect to get
<child2 />
<child3>
<sub3child />
</child3>
string. I don't care in/excluding the boundary nodes themselves since I
can correct this using PreviousSibling and NextSibling nodes.

Any simple way to do it? Or anything better/faster than IndexOf in xml
strings does not exist?

Thanks,
Jan
Jan,

If you're going to program XML, I strongly suggest you use XML APIs to do it
with, and not string manipulation. XML can behave differently than simple
strings in ways which will amaze you and waste your time.

You don't need both child2 and child4. If you have child2 as an XmlNode
called child, then child.NextSibling is your child3 element. Child3.OuterXml
will give you the string you're looking for, assuming that you're looking
for a string.

John

Aug 25 '06 #2
If you're going to program XML, I strongly suggest you use XML APIs to do
it
with, and not string manipulation. XML can behave differently than simple
strings in ways which will amaze you and waste your time.

You don't need both child2 and child4. If you have child2 as an XmlNode
called child, then child.NextSibling is your child3 element.
Child3.OuterXml will give you the string you're looking for, assuming that
you're looking for a string.

John


The problem is that I need all xml between the two elements, without knowing
what is and how many of it is between them. So this won't do.

Actually what in my special case at the moment is, that I know that these
two elements have the same parent element. So if there isn't any other way,
I'm going to find index of the first element's xml and find the second one's
and get the text between these positions. I use the same document, same
source and same provider, so I expect that they will return the same xml
string any time I will ask for it. The only problem with this method is that
I the strings could be somehow nested on the way, but I can solve this by
comparing only xml of the sibling elements.

Thanky you for reply,
Jan

Aug 25 '06 #3

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

Similar topics

0
2196
by: milkyway | last post by:
Hello, Just new to all of this. The code below is supposed to load an XML file for use in a table. It doesn't work because of one command: table.insertRow command: I have seen the specs...
4
11343
by: Andy Neilson | last post by:
I've run across a strange behaviour with XmlSerializer that I'm unable to explain. I came across this while trying to use XmlSerializer to deserialize from a the details of a SoapException. This...
1
2510
by: Randal Chapman | last post by:
Hi. I am returning a "distinct" list of nodes from an xmldocument using selectnodes. I get the list fine, and I can select individual nodes, but when I try to access the count of the list my...
8
2492
by: Todd Bright | last post by:
Is there a way to get the current XmlNode from the reader while in the validation event handler? What I'd like to do is display the error message along with the name of its parent node. In my...
9
1199
by: Mitchell Vincent | last post by:
So I have some XML exported from another database. This is greatly trimmed for brevity's sake.. <Customer> <CustomerNumber>C1000</CustomerNumber> <CustomerName>Demo Customer 1</CustomerName>...
1
1156
by: zoneal | last post by:
I'm making a "favourites" for a browser, as i may have said in previous post. So I want to be able to read a simple xml's <Url> <Favourites> <url>http://www.google.ca</url> </Favourites> Any...
2
961
by: Philip Wagenaar | last post by:
I have a xml file like: <root> <item> <car type="4wd"> <manufactored>1-1-1999</manufactored> <color>red</color> <length>2.40m</length> </car </item>
6
2631
by: ahmed.maryam | last post by:
Hi Everyone, How can I check for end elements in a XmlNodeList that consists of all the children nodes in my XML document? Can I avoid using XmlReader or XPath Navigator? Thanks for any help! ...
12
2518
by: minimalniemand | last post by:
I try to recursivley fill a treeview from a xml-file. It works well, when the contents of the xml and the treeview match 1:1. code here: http://mad-scientists.co.uk/micha/shownode.txt a sample...
0
7125
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
7002
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
7205
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
7379
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...
1
4910
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4590
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3093
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1419
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
291
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.