Note that there are some explanatory texts on larger screens.

plurals
  1. POCreate Filtered XmlNodeList
    primarykey
    data
    text
    <p>I have XML data containing image information. My first goal is to create a filtered <code>XmlNodeList</code> (ex. return all of the images where <code>color == yellow</code>). The ultimate goal is to be able to return a list of names of images where <code>color == yellow</code> (returning an entire filtered <code>XmlNodeList</code> is great, but I will really just need one element within that filtered list, such as a name or id).</p> <p>In my case, the root node is called <code>Images</code>, and I want to be able to search amongst each <code>Image</code> node. My XML data has no XML attributes, so every bit of data is represented as an element (making the color 'yellow' a child node of an image, not an attribute of an image).</p> <p>XML</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt; &lt;Images xmlns="http://oec.api.opsource.net/schemas/server" xmlns:ns9="http://oec.api.opsource.net/schemas/multigeo" xmlns:ns5="http://oec.api.opsource.net/schemas/vip" xmlns:ns12="http://oec.api.opsource.net/schemas/storage" xmlns:ns6="http://oec.api.opsource.net/schemas/whitelabel" xmlns:ns13="http://oec.api.opsource.net/schemas/manualimport" xmlns:ns7="http://oec.api.opsource.net/schemas/datacenter" xmlns:ns10="http://oec.api.opsource.net/schemas/reset" xmlns:ns8="http://oec.api.opsource.net/schemas/general" xmlns:ns11="http://oec.api.opsource.net/schemas/support" xmlns:ns2="http://oec.api.opsource.net/schemas/directory" xmlns:ns4="http://oec.api.opsource.net/schemas/network" xmlns:ns3="http://oec.api.opsource.net/schemas/organization"&gt; &lt;Image&gt; &lt;id&gt;mcd93jf8dd&lt;/id&gt; &lt;name&gt;cat&lt;/name&gt; &lt;color&gt;yellow&lt;/color&gt; &lt;/Image&gt; &lt;Image&gt; &lt;id&gt;d4b8l23sas&lt;/id&gt; &lt;name&gt;dog&lt;/name&gt; &lt;color&gt;yellow&lt;/color&gt; &lt;/Image&gt; &lt;/Images&gt; </code></pre> <p>My original source of XML data is a stream. I have figured out ways of iterating through the different levels of my XML hierarchy using foreach loops, but I keep running into issues of not having all the methods available that I need on child nodes. Advice elsewhere seems to suggest using <code>XPath</code> to implement my filter, but I could not get that to work with what I have got thus far:</p> <p>C#</p> <pre><code>//'stream' previously defined as a Stream XmlReader reader = XmlReader.Create(stream); XmlDocument xml = new XmlDocument(); xml.Load(reader); XmlElement root = xml.DocumentElement; XmlNodeList images = root.ChildNodes; foreach (XmlNode image in images) { XmlNodeList attributes = image.ChildNodes; foreach (XmlNode attribute in attributes) { //do stuff } } </code></pre>
    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.
    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