如何使用xPathNavigator从根获取属性值

时间:2018-06-20 14:24:51

标签: c# xml xpath

我尝试像这样从xmlns属性获取痛苦的类型:

XPathNavigator pymntsTypeNode = 
mPymntsNavigator.SelectSingleNode("Document");
        bool success = pymntsTypeNode.MoveToFirstAttribute();

        if (success)
        {
            if (pymntsTypeNode.Value.Contains("pain.001") || pymntsTypeNode.Value.Contains("pain.008"))
            {
                return pymntsTypeNode.Value;
            }
            throw new Exception("invalid attribute of payment type");
        }

来自此xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<Document xmlns="urn:iso:std:iso:20022:tech:xsd:pain.001.001.03" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<CstmrCdtTrfInitn>
<GrpHdr>
...
...
...

0 个答案:

没有答案