Click here to Skip to main content
15,888,984 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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>


What I have tried:

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;
                        }
                    }
Posted
Updated 23-Aug-19 8:41am

1 solution

I try this way:
var doc = new XmlDocument();
doc.LoadXml(_xml);
string CFOP= doc.GetElementsByTagName("CFOP")[0].InnerText;


see xml document
 
Share this answer
 
v5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900