Skip to main content

Microsoft Silverlight

Answered Question Parsing XMLRSS Feed

(0)

Gamewolf
Gamewolf

Member

Member

89 points

72 Posts

Parsing XML

I am wanting to parse simple XML in Silverlight 2 Beta 2. I have searched google and the forums, but cannot find something simple. All I want is to have a simple xml file like this:

<node>

<node2>TextTextText</node2>

</node>

 

and in my Silverlight, a textblock will say whatever node2 is. I cannot find anything simple like this anywhere. Everything is always very complicated and whatnot. Anyone know how to do this? Thanks.

--
Gamewolf

Leonid Andruhin
Leonid A...

Member

Member

632 points

135 Posts

Re: Parsing XML

You can analyse text if it so simple:

sXML = "your xml";

if(sXML.Contains("<YourNodeName>"))

{

sData = sXML.Substring(sXML.IndexOf("<YourNodeName>") + "<YourNodeName>".Length, sXML.IndexOf("</YouNodeName>") - sXML.IndexOf("YourNodeName") - "YourNodeName".Length);

}

else //your data is null or string.Empty

{

sData = "";

}

robhouweling
robhouwe...

Contributor

Contributor

3158 points

540 Posts

Silverlight MVP
Answered Question

Re: Parsing XML

This oneliner also does the trick (include System.Xml.Linq):

XElement elem =new XElement("node", new XElement("node2", myTextBox.Text));

elem.ToString() returns the xml string.

(If this has answered your question, please click on mark as answer on this post)

Cheers!
Rob Houweling



My blog

Gamewolf
Gamewolf

Member

Member

89 points

72 Posts

Re: Parsing XML

Ok, Thanks.

--
Gamewolf
  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities