Note that there are some explanatory texts on larger screens.

plurals
  1. POC# XPath help - Expression not working
    primarykey
    data
    text
    <p>Here is an example XML doc that matches the one I am getting info from:</p> <pre><code>&lt;?xml version="1.0" standalone="yes"?&gt; &lt;Products xmlns="http://tempuri.org/Products.xsd"&gt; &lt;Movies&gt; &lt;Title&gt;Title1&lt;/Title&gt; &lt;Language&gt;English&lt;/Language&gt; &lt;/Movies&gt; &lt;Movies&gt; &lt;Title&gt;Title2&lt;/Title&gt; &lt;Language&gt;English&lt;/Language&gt; &lt;/Movies&gt; &lt;Movies&gt; &lt;Title&gt;Title3&lt;/Title&gt; &lt;Language&gt;French&lt;/Language&gt; &lt;/Movies&gt; &lt;Books&gt; &lt;Title&gt;BTitle1&lt;/Title&gt; &lt;Genre&gt;Suspense&lt;/Genre&gt; &lt;/Books&gt; &lt;Books&gt; &lt;Title&gt;BTitle2&lt;/Title&gt; &lt;Genre&gt;Suspense&lt;/Genre&gt; &lt;/Books&gt; &lt;Books&gt; &lt;Title&gt;BTitle3&lt;/Title&gt; &lt;Genre&gt;SciFi&lt;/Genre&gt; &lt;/Books&gt; &lt;Books&gt; &lt;Title&gt;BTitle4&lt;/Title&gt; &lt;Genre&gt;SciFi&lt;/Genre&gt; &lt;/Books&gt; &lt;/Products&gt; </code></pre> <p>Here is my code to get all books with the genre of Suspense:</p> <pre><code>//Get state list using XPath XPathDocument xDoc = new XPathDocument(xmlPath); //Path to my file XPathNavigator xNav = xDoc.CreateNavigator(); string booksQuery = "Books[Genre = \"Suspense\"]"; XPathNodeIterator xIter = xNav.Select(booksQuery); while (xIter.MoveNext()) { //do stuff with xIter.Current } </code></pre> <p>I have tried several queries including <code>Products/Books[Genre = \"Suspense\"]</code>, <code>Products/Books</code>, <code>./Books</code>, and <code>Books</code>. My xIter always has zero items.</p> <p>I'm new to XPath, so I'm sure it's a really simple error, but maybe not. I know I can get a DataSet with the tables [Movies] and [Books] out of this XML file using <code>myDataSet.ReadXml(myXmlPathString);</code> so the XML file is not corrupt. If that helps any.</p> <p>So, my question ... what am I doing wrong?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload