Groups | Blog | Home
all groups > dotnet xml > april 2005 >

dotnet xml : xpath problems


juli jul
4/5/2005 12:28:09 AM
Hello,
I am trying to get all the elements that are inside the <group> tag in
this function and it doesn't work.
What is wrong with that?

private void populateTreeControl(
System.Xml.XmlNode document,
System.Windows.Forms.TreeNodeCollection nodes)
{
XmlNodeList xmn = document.SelectNodes("/sectionGroup/*");



foreach (System.Xml.XmlNode node in
document)
{


string text = (node.Value != null ? node.Value :
(node.Attributes != null &&
node.Attributes.Count > 0 ) ?
node.Attributes[0].Value : node.Name);
TreeNode new_child = new TreeNode(text);
nodes.Add(new_child);
populateTreeControl(node, new_child.Nodes);


}
}

Thanks a lot!




juli jul
4/5/2005 2:28:09 AM

Sorry,I meant the sectionGroup tag.
xml:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name = "abc">
<section name = "Memory" type =
"System.Configuration.DictionarySectionHandler" />
<section name="base" type=
"System.Configuration.DictionarySectionHandler" />

</sectionGroup>
</configSections>
</configuration>

I want to get all the information inside the sectionGroup tag,what am I
doing wrong?
Thanks a lot!

juli jul
4/5/2005 4:39:56 AM

thanks but it's not working,I get results only if I am doing soething
like that:
XmlNodeList xmn = document.SelectNodes("*");
Why all the other xpath queries don't return any result?


juli jul
4/5/2005 6:38:16 AM
I get this error when doing it:
'System.Xml.XmlNode' does not contain a definition for 'DocumentElement'

And what xpath expression can I make in order to get all the elements
except the sectionGroup elemets?
Thank you!


Dennis Myrén
4/5/2005 9:37:50 AM
I cannot see that you try to select any <group> tag.

You should provide a sample of the XML and let us know what you want to
extract.
--
Regards,
Dennis JD Myrén
Oslo Kodebureau
[quoted text, click to view]

Dennis Myrén
4/5/2005 11:39:31 AM
Alright, if you want to get all the <section> nodes :
doc.DocumentElement.SelectNodes("configSections/section");
Anty children of configSections:
doc.DocumentElement.SelectNodes("configSections/*");
or
doc.DocumentElement.SelectSingleNode("configSections").ChildNodes;

--
Regards,
Dennis JD Myrén
Oslo Kodebureau
[quoted text, click to view]

Dennis Myrén
4/5/2005 12:58:11 PM
Sorry, it should be:
doc.DocumentElement.SelectNodes("configSections/sectionGroup/section");
to get all sections and
doc.DocumentElement.SelectNodes("configSections/sectionGroup");
to get all sectionGroup

--
Regards,
Dennis JD Myrén
Oslo Kodebureau
[quoted text, click to view]

Dennis Myrén
4/5/2005 2:54:30 PM
doc.DocumentElement.SelectNodes("configSections/sectionGroup/section");
where "doc" is your is your instance of *XmlDocument*, not XmlNode.

To get all children of configSection except sectionGroup:
doc.DocumentElement.SelectNodes("configSections[name() != 'sectionGroup']");

--
Regards,
Dennis JD Myrén
Oslo Kodebureau
[quoted text, click to view]

AddThis Social Bookmark Button