Click here to Skip to main content
13,006,002 members (106,695 online)
Rate this:
Please Sign up or sign in to vote.
See more:
I am trying to select some elements from the xml document. Syntax of XPath is hard, I haven't found some good tutorial for it, but I have a program BaseX, which displays a XQuery route to the selected element. In a C# code I am trying to reach this element and add it to a list. but it throws this error: '/descendant-or-self::*:Test[.//*:Value contains text "value1"]' has an invalid token.
Can anyone write 3 valid XPath codes to some elements from the following XML (not like /DataSet)? Does anybody know about some good program for XPath? Or can anyone solve the error and write a correct XPath to the element I am trying to reach?

Error at:
XmlNodeList list = xml.SelectNodes(tbXPath.Text);

C# code:
protected void btnSelect_Click(object sender, EventArgs e)
        XmlDocument xml = new XmlDocument();
        xml.Load("C:/Users/Peta3nec/Documents/Visual Studio 2010/WebSites/Beach_Volleyball/DataSets/DataSet_Zkouška.xml");
        XmlNodeList list = xml.SelectNodes(tbXPath.Text);
        GridView1.DataSource = list;

  <xs:schema xmlns:xs="" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="NewDataSet">
    <xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
        <xs:choice minOccurs="0" maxOccurs="unbounded">
          <xs:element name="Forum">
                <xs:element name="ID" type="xs:int"/>
                <xs:element name="Datum" type="xs:dateTime" minOccurs="0"/>
                <xs:element name="Player_ID" type="xs:string" minOccurs="0"/>
                <xs:element name="Zprava" type="xs:string" minOccurs="0"/>
          <xs:element name="Test">
                <xs:element name="ID" type="xs:int"/>
                <xs:element name="Value" type="xs:string" minOccurs="0"/>
      <xs:unique name="Constraint1" msdata:PrimaryKey="true">
        <xs:selector xpath=".//Forum"/>
        <xs:field xpath="ID"/>
      <xs:unique name="Test_Constraint1" msdata:ConstraintName="Constraint1" msdata:PrimaryKey="true">
        <xs:selector xpath=".//Test"/>
        <xs:field xpath="ID"/>
  <diffgr:diffgram xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
      <Forum diffgr:id="Forum1" msdata:rowOrder="0" diffgr:hasChanges="inserted">
        <Zprava>Fórum je v provozu děcka!</Zprava>
      <Forum diffgr:id="Forum2" msdata:rowOrder="1" diffgr:hasChanges="inserted">
        <Zprava>To je GridView, jo? :-D</Zprava>
      <Test diffgr:id="Test1" msdata:rowOrder="0" diffgr:hasChanges="inserted">
      <Test diffgr:id="Test2" msdata:rowOrder="1" diffgr:hasChanges="inserted">
      <Test diffgr:id="Test3" msdata:rowOrder="2" diffgr:hasChanges="inserted">
      <Test diffgr:id="Test4" msdata:rowOrder="3" diffgr:hasChanges="inserted">
      <Test diffgr:id="Test5" msdata:rowOrder="4" diffgr:hasChanges="inserted">
      <Test diffgr:id="Test6" msdata:rowOrder="5" diffgr:hasChanges="inserted">
      <Test diffgr:id="Test7" msdata:rowOrder="6" diffgr:hasChanges="inserted">
      <Test diffgr:id="Test8" msdata:rowOrder="7" diffgr:hasChanges="inserted">
      <Test diffgr:id="Test9" msdata:rowOrder="8" diffgr:hasChanges="inserted">
      <Test diffgr:id="Test10" msdata:rowOrder="9" diffgr:hasChanges="inserted">
Posted 11-Dec-12 2:23am
CHill60 11-Dec-12 10:00am
What is in tbXPath.Text ?

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170628.1 | Last Updated 11 Dec 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100