SelectNodes

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I made an application which uses SelectNodes method from XmlNode. I just found that this method is not supported in Compact framework. Do you know a way to replace this method or somehow to populate the XmlNodeList

Thank you
 
If you use XmlElement instead of XmlNode for your nodes you can use the
GetElementsByTagName function which returns a XmlNodeList.

Something like this:

XmlNodeList Xnodes = Xdoc.DocumentElement.GetElementsByTagName(KeyName);

if (Xnodes.Count > 0)

{

Xnodes[0].InnerText = Value;

}

else

{

XmlNode Xnode = Xdoc.CreateNode(XmlNodeType.Element,KeyName,"");

Xnode.InnerText = Value;

Xdoc.DocumentElement.AppendChild(Xnode);

}

Cristi said:
I made an application which uses SelectNodes method from XmlNode. I just
found that this method is not supported in Compact framework. Do you know a
way to replace this method or somehow to populate the XmlNodeList?
 
As an aside to this, I've tried this method, and using the
XMLTextreader, and also loading the XML directly into the dataset.

I was interested in performance mainly, because my app was using XML
files to persist settings and reading them on startup.

The XMLTextReader (esp. in SP2) performs pretty good, followed by this
approach below (navigating the DOM, more or less); loading the XML
into a dataset and persisting the data there is actually fairly
horrendous in performance. (Tests on an Ipaq2215.)

I'm guessing this isn't a surprise, really, but the data I was working
with consisted of 3 xml files with about 100 elements in total. The
times, respectively, were 1.5, 2.5, and 4 seconds... which is a pretty
big difference IMO!

-Tom


Isaias Formacio Serna said:
If you use XmlElement instead of XmlNode for your nodes you can use the
GetElementsByTagName function which returns a XmlNodeList.

Something like this:

XmlNodeList Xnodes = Xdoc.DocumentElement.GetElementsByTagName(KeyName);

if (Xnodes.Count > 0)

{

Xnodes[0].InnerText = Value;

}

else

{

XmlNode Xnode = Xdoc.CreateNode(XmlNodeType.Element,KeyName,"");

Xnode.InnerText = Value;

Xdoc.DocumentElement.AppendChild(Xnode);

}

Cristi said:
I made an application which uses SelectNodes method from XmlNode. I just
found that this method is not supported in Compact framework. Do you know a
way to replace this method or somehow to populate the XmlNodeList?
Thank you
 
Back
Top