Nodelist grab from C # .net nodelist

The following code gives me a nodeList to repeat:

XPathNavigator thisNavigator = thisXmlDoc.CreateNavigator();
XPathNodeIterator dossierNodes = thisNavigator.Select("changedthisname/dossiers/dossier");

I am processing this nodeList and I need to take another nodelist from this list. I am trying to do this using this code:

XPathNavigator alineanodesNavigator = dossierNodes.Current;
XPathNodeIterator alineaNodes = alineanodesNavigator.Select("/dossier/alineas/alinea");

I use this code inside a while loop (dossierNodes.MoveNext ()) and want this nodelist to be populated by all "allinea's". However, I am not getting any results back to the alineaNodes iterator.

The structure of the document is as follows:

alt text

How to get alinea nodes from the current node dossier ??

I was debugging, and it turned out:

alt text

    Stream responseStream = response.GetResponseStream();
    StreamReader reader = new StreamReader(responseStream, System.Text.Encoding.UTF8);
    string xml = reader.ReadToEnd();
    XmlDocument thisXmlDoc = new XmlDocument();
    thisXmlDoc.LoadXml(xml);

    XPathNavigator thisNavigator = thisXmlDoc.CreateNavigator();
+3
source share
5 answers

Right full path

changedthisname/dossiers/dossier/alineas/alinea

So, if you first choose changedthisname/dossiers/dossier, then the relative path:

alineas/alinea
+3

node, , "/" XPath, " node" , node. XPath :

EDIT:

. .

"/alineas/Alinea"

.

+2

, .

, alinea xpath, SelectDescendants node, :

            XPathNavigator alineanodesNavigator = dossierNodes.Current;
            XPathNodeIterator alineaNodes = alineanodesNavigator.SelectDescendants("alinea", "", false);


            List<Alinea> thisAlineaList = new List<Alinea>();
0

Select() XPath: "//alinea".

alineas:

        XPathNavigator thisNavigator = doc.CreateNavigator();
        XPathNodeIterator dossierNodes = thisNavigator.Select("//dossier");
        while (dossierNodes.MoveNext())
        {
            XPathNavigator alineanodesNavigator = dossierNodes.Current;
            XPathNodeIterator alineaNodes = alineanodesNavigator.Select("//alinea");

            while (alineaNodes.MoveNext())
            {

            }
        }
0

Linq to XML .

var alineaNodes = from alinea in XDocument.Load(alldata.xml).Descendents("alinea")
                  select alinea;

which returns IEnumerable with all elements in alldata.xml. Hope this helps. And really, look at Linq, which is great for these things.

-1
source

Source: https://habr.com/ru/post/1762854/


All Articles