Groups | Blog | Home
all groups > dotnet xml > june 2004 >

dotnet xml : read a part of file xml


Fabrizio Di Giovambattista via .NET 247
6/5/2004 12:20:14 PM
(Type your message here)

--------------------------------
From: Fabrizio Di Giovambattista

Good evening,
I can read a part of xml file and
i must create an xmldocument with it.
Thanks

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

Oleg Tkachenko [MVP]
6/6/2004 1:25:03 PM
[quoted text, click to view]

Read the document with XmlTextReader till the element you want and then
load it into XmlDocument:

string xml = "<foo><bar>fffff</bar></foo>";
XmlTextReader r = new XmlTextReader(new StringReader(xml));
XmlDocument doc = new XmlDocument();
while (r.Read())
{
if (r.Name == "bar")
doc.Load(r);
}
r.Close();
doc.Save(Console.Out)

--
Oleg Tkachenko [XML MVP]
AddThis Social Bookmark Button