This is Interesting: Free Magazines for Graphics designers and webmasters
Home > Archive > Microsoft XML > September 2005 > Returning subset of xml document as string
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 |
Returning subset of xml document as string
|
|
|
| Hi,
I have a problem with finding a particular XML fragment within a document. I
want to locate the XML fragment within a document containing a given node,
its children, and grandchildren, and write that subset of the document as a
string (including all XML the tags and attributes) to a database table.
Using .net and XPath I can locate the node I wish to find, and get a
XPathNodeIterator back, but this doesn't give me the structure with all the
xml tags. Is there a way to select a "subdocument" of nodes from an
xmldocument and return it as a string including the structure?
Any help would be appreciated.
Regards,
Onur
| |
|
| Try the following code snippet.
using System;
using System.Xml;
using System.Threading;
namespace loadxml
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
XmlDocument doc = new XmlDocument();
doc.Load(new XmlTextReader(@"D:\fruitfruit.xml"));
XmlNode node = doc.SelectSingleNode(@"/NewDataSet/Table");
Console.WriteLine(node.OuterXml);
Thread.Sleep(5000);
}
}
}
and the XML file looks like the following:
<NewDataSet>
<Table>
<name>onega</name>
<url>www.fruitfruit.com</url>
</Table>
</NewDataSet>
"Onur" <Onur@discussions.microsoft.com> wrote in message
news:81A07AD3-3D28-4B92-9CB6-4948D72E3474@microsoft.com...
> Hi,
> I have a problem with finding a particular XML fragment within a document.
> I
> want to locate the XML fragment within a document containing a given node,
> its children, and grandchildren, and write that subset of the document as
> a
> string (including all XML the tags and attributes) to a database table.
>
> Using .net and XPath I can locate the node I wish to find, and get a
> XPathNodeIterator back, but this doesn't give me the structure with all
> the
> XML tags. Is there a way to select a "subdocument" of nodes from an
> xmldocument and return it as a string including the structure?
>
> Any help would be appreciated.
>
> Regards,
>
> Onur
|
|
|
| | Copyright 2003 - 2008 forum4designers.com Software forum Computer Hardware reviews |
|