473,408 Members | 2,477 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

xpath problems

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!


*** Sent via Developersdex http://www.developersdex.com ***
Nov 12 '05 #1
7 2669
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
"juli jul" <ju******@yahoo.com> wrote in message
news:uW**************@tk2msftngp13.phx.gbl...
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!


*** Sent via Developersdex http://www.developersdex.com ***

Nov 12 '05 #2

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!

*** Sent via Developersdex http://www.developersdex.com ***
Nov 12 '05 #3
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("configSectio ns").ChildNodes;

--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"juli jul" <ju******@yahoo.com> wrote in message
news:ue**************@TK2MSFTNGP09.phx.gbl...

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!

*** Sent via Developersdex http://www.developersdex.com ***

Nov 12 '05 #4

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?
*** Sent via Developersdex http://www.developersdex.com ***
Nov 12 '05 #5
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
"juli jul" <ju******@yahoo.com> wrote in message
news:ua**************@TK2MSFTNGP10.phx.gbl...

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?
*** Sent via Developersdex http://www.developersdex.com ***

Nov 12 '05 #6
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!
*** Sent via Developersdex http://www.developersdex.com ***
Nov 12 '05 #7
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
"juli jul" <ju******@yahoo.com> wrote in message
news:OY*************@TK2MSFTNGP15.phx.gbl...
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!
*** Sent via Developersdex http://www.developersdex.com ***

Nov 12 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: bdinmstig | last post by:
I refined my attempt a little further, and the following code does seem to work, however it has 2 major problems: 1. Very limited support for XPath features Basic paths are supported for...
13
by: tfsquare | last post by:
All, I am new to XSLT and having some problems understanding the syntax of XPath which selects nodes in the XML document. Consider this bit of XML, which contains three outer XML elements. ...
6
by: Ramon M. Felciano | last post by:
Helo all -- I'm trying to gain a deeper understand for what type of semi-declarative programming can be done through XML and XPath/XSLT. I'm looking at graph processing problems as a testbed for...
2
by: Anna | last post by:
Hi all. I am using Jaxen to evaluate XPath expressions in Java. I encountered problems when comparing results returned by jaxen with results returned by other XPath implementation - I was using...
4
by: Vitali Gontsharuk | last post by:
Hallo! When using the XPATH document() function to load a new XML document, we are coming across problems, because XALAN seems to have problems with absolute paths. XALAN always assumes that the...
2
by: ree32 | last post by:
When I import an xml document in Visual studio and Genereate as schema from it, and create a dataset from it, it adds this line into to the root element of my xml file -...
5
by: Chua Wen Ching | last post by:
Hi, I read from this tutorial at codeproject Question A: http://www.codeproject.com/csharp/GsXPathTutorial.asp regarding xpath.. but i try to apply in my situation, and can't get it...
14
by: Mat| | last post by:
Hello :-) I am learning XPath, and I am trying to get child nodes of a node whose names do *not* match a given string, e.g : <dummy> <example> <title>Example 1</title> <body>this is an...
7
by: Tim Hallwyl | last post by:
Hi, there! As I understand the XPaht recommendation, the context node is a node; not a node-list, not XPath object -- but a single node. Now, the WS-BPEL 2.0 specification allows an XML simple...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.