Note that there are some explanatory texts on larger screens.

plurals
  1. POLinq to XML - how do I get this element value
    primarykey
    data
    text
    <p>Fairly simple one, but my knowledge is limited in this area. I'm using the following c# code to access the value of elements within my <code>SGML and XML documents</code>. </p> <p>It's working fine when there is only one element with the given name in the document, but as soon as there are more than one element with the same name it throws an exception, obviously!</p> <p>I need to use xpath or some other way of specifying the location of the element i'm trying to get the value of.</p> <pre><code> XDocument doc = XDocument.Load(sgmlReader); string system = doc.Descendants("chapnum").Single().Value; return system; </code></pre> <p>This works fine, if there is only one "<code>chapnum</code>" in the doc, but i need to specifically get the value of "<code>chapnum</code>" at the following nested location "<code>dmaddres/chapnum</code>".</p> <p>How please?</p> <p>Here is a sample of the xml doc. I'm trying to get the value of the "<code>chapnum</code>" element nested in the "<code>dmaddress</code>" element.</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;!DOCTYPE dmodule []&gt; &lt;dmodule xmlns:dc="http://www.purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.s1000d.org/S1000D_2-3-1/xml_schema_flat/descript.xsd"&gt; &lt;idstatus&gt; &lt;dmaddres&gt; &lt;dmc&gt;&lt;avee&gt;&lt;modelic&gt;xx&lt;/modelic&gt;&lt;sdc&gt;A&lt;/sdc&gt;&lt;chapnum&gt;29&lt;/chapnum&gt; &lt;section&gt;1&lt;/section&gt;&lt;subsect&gt;3&lt;/subsect&gt;&lt;subject&gt;54&lt;/subject&gt;&lt;discode &gt;00&lt;/discode&gt;&lt;discodev&gt;AAA&lt;/discodev&gt;&lt;incode&gt;042&lt;/incode&gt;&lt;incodev &gt;A&lt;/incodev&gt;&lt;itemloc&gt;D&lt;/itemloc&gt;&lt;/avee&gt;&lt;/dmc&gt; &lt;dmtitle&gt;&lt;techname&gt;Switch&lt;/techname&gt;&lt;infoname&gt;Description of function&lt;/infoname&gt; &lt;/dmtitle&gt; &lt;issno inwork="00" issno="001" type="new"/&gt; &lt;issdate day="20" month="07" year="2012"/&gt; &lt;language language="sx"/&gt;&lt;/dmaddres&gt; &lt;status&gt; &lt;security class="01"/&gt;&lt;datarest&gt;&lt;instruct&gt;&lt;distrib&gt;-&lt;/distrib&gt;&lt;expcont &gt;Obey the national regulations for export control.&lt;/expcont&gt;&lt;/instruct&gt; &lt;inform&gt;&lt;copyright&gt;&lt;para&gt;&lt;refdm&gt;&lt;avee&gt;&lt;modelic&gt;xx&lt;/modelic&gt;&lt;sdc&gt;A&lt;/sdc&gt; &lt;chapnum&gt;29&lt;/chapnum&gt;&lt;section&gt;1&lt;/section&gt;&lt;subsect&gt;3&lt;/subsect&gt;&lt;subject &gt;54&lt;/subject&gt;&lt;discode&gt;00&lt;/discode&gt;&lt;discodev&gt;ZZZ&lt;/discodev&gt;&lt;incode &gt;021&lt;/incode&gt;&lt;incodev&gt;Z&lt;/incodev&gt;&lt;itemloc&gt;D&lt;/itemloc&gt;&lt;/avee&gt;&lt;/refdm &gt;&lt;/para&gt;&lt;/copyright&gt;&lt;datacond&gt;BREXREF=AJ-A-00-00-00-05ZZZ-022Z-D VERSUB=CDIM-V6&lt;/datacond&gt; &lt;/inform&gt;&lt;/datarest&gt; &lt;rpc&gt;xxxxx&lt;/rpc&gt; &lt;orig&gt;xxxxx&lt;/orig&gt; &lt;applic&gt; &lt;type&gt;-&lt;/type&gt; &lt;model model="xxxxx"&gt;&lt;mfc&gt;xxxxx&lt;/mfc&gt;&lt;pnr&gt;xxxxxxx&lt;/pnr&gt;&lt;/model&gt; &lt;/applic&gt; &lt;brexref&gt;&lt;refdm&gt;&lt;avee&gt;&lt;modelic&gt;xx&lt;/modelic&gt;&lt;sdc&gt;A&lt;/sdc&gt;&lt;chapnum&gt;00&lt;/chapnum&gt; &lt;section&gt;0&lt;/section&gt;&lt;subsect&gt;0&lt;/subsect&gt;&lt;subject&gt;00&lt;/subject&gt;&lt;discode &gt;05&lt;/discode&gt;&lt;discodev&gt;ZZZ&lt;/discodev&gt;&lt;incode&gt;022&lt;/incode&gt;&lt;incodev &gt;Z&lt;/incodev&gt;&lt;itemloc&gt;D&lt;/itemloc&gt;&lt;/avee&gt;&lt;/refdm&gt;&lt;/brexref&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
    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