找不到Xml元素

时间:2017-04-28 03:22:45

标签: c# xml linq-to-xml

我试图操纵XML文件,但我遇到了问题。 目前,我试图让标签值突出显示在下方,但我没有得到它。

XML文件

<!-- language:xml -->
<cteProc versao="2.00" xmlns="http://www.portalfiscal.inf.br/cte">
    <CTe xmlns="http://www.portalfiscal.inf.br/cte">
        <infCte versao="2.00" Id="CTe35170208310367000113570010001828261272183608">
            <ide>
                <cUF>35</cUF>
                <cCT>27218360</cCT>
                <CFOP>5353</CFOP>
                <natOp>Prest. Serv. Transporte A Estab. Comercial</natOp>
                <forPag>2</forPag>
                <mod>57</mod>
                <serie>1</serie>
                <nCT>182826</nCT>
                <dhEmi>2017-02-13T08:57:27</dhEmi>
                <tpImp>1</tpImp>
                <tpEmis>1</tpEmis>
            </ide>
            <compl>
                <Entrega>
                    <semData>
                        <tpPer>0</tpPer>
                    </semData>
                    <semHora>
                        <tpHor>0</tpHor>
                    </semHora></Entrega>
                </compl>
                <vPrest>
                    <vTPrest>2440.00</vTPrest>
                    <vRec>2440.00</vRec>
                    <Comp>
                        <xNome>Frete</xNome>
                        <vComp>2147.20</vComp>
                    </Comp>
                </vPrest>
                <infCTeNorm>
                    <infCarga>
                        <vCarga>0.00</vCarga>
                        <proPred>jkfhmjhmh</proPred>
                        <infQ>
                            <cUnid>00</cUnid>
                            <tpMed>LITRAGEM</tpMed>
                            <qCarga>1000.0000</qCarga>
                        </infQ>
                    </infCarga>
                </infCTeNorm>
            </infCte>
            <Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
                <SignedInfo>
                    <CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315" />
                    <SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" />
                    <Reference URI="#CTe35170208310367000113570010001828261272183608">
                        <Transforms>
                            <Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature" />
                            <Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315" />
                        </Transforms>
                        <DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
                        <DigestValue>VlX1bKhOHjQb5QCv6TliOoMFmwA=</DigestValue>
                    </Reference>
                </SignedInfo>
                <SignatureValue>xxxxxxxxxxxx</SignatureValue>
                <KeyInfo>
                    <X509Data><X509Certificate>xxxxxxxxxxxxxx</X509Certificate></X509Data>
                </KeyInfo>
            </Signature>
        </CTe>
        <protCTe versao="2.00">
            <infProt>
                <tpAmb>2</tpAmb>
                <verAplic>SP-CTe-22-12-2016</verAplic>
                **<chCTe>xxxxxxxxxxxxxxxxxxxxxxxxxx</chCTe>**
                <dhRecbto>2017-02-13T09:09:08</dhRecbto>
                <nProt>135170007940102</nProt>
                <digVal>VlX1bKhOHjQb5QCv6TliOoMFmwA=</digVal>
                <cStat>100</cStat>
                <xMotivo>Autorizado o uso do CT-e</xMotivo>
            </infProt>
        </protCTe>
    </cteProc>

我试图获取标签&#34;&lt; ** chCTe&gt; xxxxxxxxxxxxxxxxxxxxxxxxxx&#34; ,但始终返回null

代码

XDocument doc = XDocument.Load("file_1.xml");
var c = from a in doc.Descendants("chCTe") select a;

1 个答案:

答案 0 :(得分:0)

sys.argv[1]