This is Interesting: Free Magazines for Graphics designers and webmasters
Home > Archive > Microsoft XML > August 2006 > XML between two XmlNodes
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
XML between two XmlNodes
|
|
| Jan Kucera 2006-08-25, 6:43 pm |
| 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
| |
| John Saunders 2006-08-25, 6:43 pm |
| "Jan Kucera" <kucera@lupacovka.cz> wrote in message
news:787BA160-3807-4DEA-AD76-F91A40E602F9@microsoft.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
| |
| Jan Kucera 2006-08-25, 6:43 pm |
|
> 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
|
|
|
| | Copyright 2003 - 2008 forum4designers.com Software forum Computer Hardware reviews |
|