Skip to main content
Home Forums General Silverlight Getting Started XMLDocument,XMLNodeList in Silverlight
4 replies. Latest Post by juliako on December 9, 2008.
(0)
petit_a
Member
2 points
6 Posts
10-12-2008 9:45 AM |
Hi, Can anyone tell me what I can write instead of XMLDocument and XMLNodeList in Silverlight?I've read forums and found that I should use XDocument which is from system.linq, but it is not working.I get the error below The type or namespace "XDocument" can not be found(are you missing a using directive or an assembly reference?) I'm trying to write a parser and have never done it before so I'm having a hard time.Can someone please give me a simple instruction? Thanks
Bill Reiss
Contributor
4840 points
919 Posts
10-12-2008 10:27 AM |
You need to add a reference to the System.Xml.Linq.dll in your Silverlight application project. Once you do this you should be able to use XDocument, etc.
10-12-2008 12:46 PM |
Thank you Bill.Now I can use XDocument but I can't use XmlNodeList or XDocument.readnode(),... Here is what I'm trying to write XmlNodeList configs = xmlDocument.ReadNode(XmlReader.Create("config.xml")).ChildNodes; Can you help me with that?Thanks
Jonathan...
All-Star
24939 points
2,425 Posts
10-17-2008 3:55 AM |
Hi Petit_a,
petit_a:Here is what I'm trying to write XmlNodeList configs = xmlDocument.ReadNode(XmlReader.Create("config.xml")).ChildNodes;
Please take a look at this article. A sample provides there.
public PropertyBag (XmlDocument source) { //((WaitCallback)delegate //{ fillTheBag(source.ChildNodes); //}).BeginInvoke(null, null, null); }
void fillTheBag(XmlReader root) { int depth = root.Depth; KeyValuePair<string, string> last = new KeyValuePair<string, string>(); while (root.Read()) { switch (root.NodeType) { case XmlNodeType.Text: last = new KeyValuePair<string, string>(root.Name, root.Value); break; case XmlNodeType.EndElement: if (last.Key == string.Empty && last.Value != string.Empty) { last = new KeyValuePair<string, string>(root.Name, last.Value); base.Add(last); last = new KeyValuePair<string,string>(); } if (depth > root.Depth) return; break; } if (root.IsEmptyElement || root.EOF) return; else if (root.IsStartElement()) { string name = root.Name; if (root.HasAttributes) {
while (root.MoveToNextAttribute()) { base.Add(new KeyValuePair<string, string>(root.Name, root.Value)); } root.Read(); if (root.NodeType == XmlNodeType.CDATA && root.Value.Length == 0) { root.Read(); } if (root.NodeType == XmlNodeType.Text && root.ValueType == typeof(string) && root.Value != string.Empty) { base.Add(new KeyValuePair<string, string>(name, root.Value)); } if (root.NodeType == XmlNodeType.EndElement && root.Name.Equals(name)) { root.Read(); if (root.Depth < depth) return; else continue; } if (root.IsStartElement()) { if (root.Depth > depth) fillTheBag(root); else continue; } root.Read(); } } } }
Best regards,
Jonathan
juliako
28 points
14 Posts
12-09-2008 4:43 PM |
Hi, you might find the following documentation helpful: http://msdn.microsoft.com/en-us/library/cc188996(VS.95).aspx.
I am the programming writer on the .Net and Silverlight .Net Managed XML team. If you have questions, you can send me an email at juliako@microsoft.com.
Thank you,
Julia