Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / August 2007

Tip: Looking for answers? Try searching our database.

Initializing XmlReader with a string

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Victor Rosenberg - 27 Aug 2007 20:42 GMT
Hey guys.
I want to move over a xml data using the XmlReader. The problem is
that the XmlReader.Create function demands (at least in .net 2.0) a
file location, while I need to provide a string of xml data instead
I know I can use the XmlDocument class, but it has to be a simpler
way.

Thanks in advance.
Henk Verhoeven - 27 Aug 2007 21:00 GMT
Hi Victor

When you use the XMLTextReader then you have an overload using a String
Reader type which is a basic string.

From the MSDN example

http://msdn2.microsoft.com/en-us/library/0ax3f4f3.aspx

string xmlData =
   @"<book>
      <title>Oberon's Legacy</title>
      <price>5.95</price>
     </book>";

   // Create the reader.
   XmlTextReader reader = new XmlTextReader(new StringReader(xmlData));
   reader.WhitespaceHandling = WhitespaceHandling.None;

   // Display each element node.
   while (reader.Read()){
      switch (reader.NodeType){
        case XmlNodeType.Element:
          Console.Write("<{0}>", reader.Name);
          break;
        case XmlNodeType.Text:
          Console.Write(reader.Value);
          break;
        case XmlNodeType.EndElement:
          Console.Write("</{0}>", reader.Name);
          break;
     }
   }

   // Close the reader.
   reader.Close();

Henk

> Hey guys.
> I want to move over a xml data using the XmlReader. The problem is
[quoted text clipped - 4 lines]
>
> Thanks in advance.
Victor Rosenberg - 28 Aug 2007 05:34 GMT
Thanks!

> Hi Victor
>
[quoted text clipped - 43 lines]
>
> > Thanks in advance.
Martin Honnen - 28 Aug 2007 14:16 GMT
> I want to move over a xml data using the XmlReader. The problem is
> that the XmlReader.Create function demands (at least in .net 2.0) a
> file location, while I need to provide a string of xml data instead
> I know I can use the XmlDocument class, but it has to be a simpler
> way.

  XmlReader.Create(new StringReader(yourStringVariable))
should do.

Signature

    Martin Honnen --- MVP XML
    http://JavaScript.FAQTs.com/


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.