Member 11426986 Ответов: 1

Получить значение из тега в XML


I need a solution to get the TAG values ​​from an XML Fiscal. I am not referring to the attribute, but to the value between the tags.
In the XML below. I need to search and return the value of TAG CFOP which is 13512.


<pre><?xml version="1.0" encoding="UTF-8"?>

-<sitProc xmlns="http://www.sites.com" versao="3.00">


-<sit xmlns="http://www.sites.com">


-<infSit versao="3.00" Id="23425234124354676578456356">


-<ide>

<cUF>45</cUF>

<cCT>246123</cCT>

<CFOP>13512</CFOP>

<natOp>Service</natOp>

<mod>98</mod>


Что я уже пробовал:

string caminho = openFileXml.FileName;
                    this.caminho = caminho;
                    XmlTextReader xmlReader = new XmlTextReader(caminho);
                    while (xmlReader.Read())
                    {
                        switch (xmlReader.NodeType)
                        {
                            case XmlNodeType.Element:
                                lbDados.Items.Add("<" + xmlReader.Name + ">");
                                txtDados.Text += "<" + xmlReader.Name + ">" + Environment.NewLine;
                                break;
                            case XmlNodeType.Text:
                                lbDados.Items.Add(xmlReader.Value);
                                txtDados.Text += xmlReader.Value + Environment.NewLine;
                                break;
                            case XmlNodeType.EndElement:
                                lbDados.Items.Add("<" + xmlReader.Name + ">");
                                txtDados.Text += "<" + xmlReader.Name + ">" + Environment.NewLine;
                                break;
                        }
                    }

1 Ответов

Рейтинг:
1

SSP0055

Я пробую этот путь:

var doc = new XmlDocument();
doc.LoadXml(_xml);
string CFOP= doc.GetElementsByTagName("CFOP")[0].InnerText;


см. раздел xml-документ