PC Review


Reply
Thread Tools Rate Thread

Converting String object to XDocument object

 
 
K Viltersten
Guest
Posts: n/a
 
      7th Apr 2009
I have a method as follows.

private String GetXMLString(){...}

It produces a string corresponding to
contents of a valid XML-document. Now,
my problem is that the class XDocument
seems not to have a constructor with
String as a parameter.

How can i easily trasform my String
into XDocument?

--
Regards
K Viltersten
 
Reply With Quote
 
 
 
 
Alberto Poblacion
Guest
Posts: n/a
 
      7th Apr 2009
"K Viltersten" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I have a method as follows.
>
> private String GetXMLString(){...}
>
> It produces a string corresponding to contents of a valid XML-document.
> Now, my problem is that the class XDocument
> seems not to have a constructor with
> String as a parameter.
>
> How can i easily trasform my String into XDocument?


You can use the method Load() to load the XDocument from a variety of
sources. One of the overloads takes a TextReader, which you can feed with a
StringReader (which derives from TextReader) connected to your String:

XDocument xd = new XDocument();
xd.Load(new StringReader(GetXMLString()));


 
Reply With Quote
 
Martin Honnen
Guest
Posts: n/a
 
      7th Apr 2009
K Viltersten wrote:
> I have a method as follows.
>
> private String GetXMLString(){...}
>
> It produces a string corresponding to contents of a valid XML-document.
> Now, my problem is that the class XDocument
> seems not to have a constructor with
> String as a parameter.
>
> How can i easily trasform my String into XDocument?


Use the static Parse method:
XDocument doc = XDocument.Parse(GetXMLString());



--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
K Viltersten
Guest
Posts: n/a
 
      7th Apr 2009
Oh, like that! All right. I also found

XDocument.Parse(String)

when i realized that i'm supposed to
use the XDocument class' statics!

Thanks!

--
Regards
K Viltersten





"Alberto Poblacion" <earthling-(E-Mail Removed)> wrote
in message news:(E-Mail Removed)...
> "K Viltersten" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>>I have a method as follows.
>>
>> private String GetXMLString(){...}
>>
>> It produces a string corresponding to contents of a valid XML-document.
>> Now, my problem is that the class XDocument
>> seems not to have a constructor with
>> String as a parameter.
>>
>> How can i easily trasform my String into XDocument?

>
> You can use the method Load() to load the XDocument from a variety of
> sources. One of the overloads takes a TextReader, which you can feed with
> a StringReader (which derives from TextReader) connected to your String:
>
> XDocument xd = new XDocument();
> xd.Load(new StringReader(GetXMLString()));
>
>


 
Reply With Quote
 
K Viltersten
Guest
Posts: n/a
 
      7th Apr 2009
Thanks.

--
Regards
K Viltersten




"Martin Honnen" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
>K Viltersten wrote:
>> I have a method as follows.
>>
>> private String GetXMLString(){...}
>>
>> It produces a string corresponding to contents of a valid XML-document.
>> Now, my problem is that the class XDocument
>> seems not to have a constructor with
>> String as a parameter.
>>
>> How can i easily trasform my String into XDocument?

>
> Use the static Parse method:
> XDocument doc = XDocument.Parse(GetXMLString());
>
>
>
> --
>
> Martin Honnen --- MVP XML
> http://JavaScript.FAQTs.com/


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Converting Object into String... Wallace Microsoft C# .NET 3 29th Mar 2006 03:47 PM
converting string to object excelleinc.com Microsoft VB .NET 3 15th Mar 2005 09:04 PM
Converting object to string. bryja_klaudiusz[at]poczta[dot]fm Microsoft C# .NET 1 1st Mar 2005 11:37 AM
Converting html string to object Wouter vanEck Microsoft ASP .NET 10 10th Jan 2005 03:03 PM
Converting String into Object Rajesh Kr Shukla Microsoft VB .NET 5 22nd Sep 2003 12:11 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:41 AM.