C# 在C中的用户界面上显示之前修改xml值#

C# 在C中的用户界面上显示之前修改xml值#,c#,xml,C#,Xml,我的c#程序读取xml并将其加载到xmldocument中。我需要先解密bankaccount number和sortcode元素,然后才能将其显示在用户界面中。下面是xml <Fatca xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://tempuri.org/TaskDetails.xsd"> &

我的c#程序读取xml并将其加载到xmldocument中。我需要先解密bankaccount number和sortcode元素,然后才能将其显示在用户界面中。下面是xml

 <Fatca xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://tempuri.org/TaskDetails.xsd">
    <AccountNumber>BI830418</AccountNumber>
      <AccountDetails>

        <AccountName>SIPP - Mr. t test</AccountName>

        <AccountNumber>BI830418</AccountNumber>

        <AccountID>83041</AccountID>

        <BankAccountDetails>

          <BankAccountID>23943</BankAccountID>

          <ContactID>2106175</ContactID>

          <BankAccountName>dffdf</BankAccountName>

          <BankAccountNumber>N14yKOOmpdmh23fmp7oNvg==</BankAccountNumber>

          <BankAccountType>0</BankAccountType>

          <BankSortCode>tz7r+uYFL6Ff86mI/mwJOQ==</BankSortCode>

          <Active>true</Active>

        </BankAccountDetails>

        <Active>true</Active>

      </AccountDetails>

      <Request>

        <AccountID>83041</AccountID>

      </Request>

    </Fatca>

BI830418
SIPP-Mr.t试验
BI830418
83041
23943
2106175
dffdf
N14yKOOmpdmh23fmp7oNvg==
0
tz7r+uYFL6Ff86mI/mwJOQ==
真的
真的
83041
我的c#代码逻辑如下。我得到了对象引用错误。你能告诉我这里出了什么错吗


document.XPathSelectElement(“//BankAccountDetails/BankAccountNumber”).Value=“Test”

名称空间给了您这个问题。我更喜欢使用XMLLINQ(XDocument)。排序和筛选会容易得多

使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用System.Xml;
使用System.Xml.Linq;
命名空间控制台应用程序1
{
班级计划
{
静态void Main(字符串[]参数)
{
字符串xml=
"" +
“BI830418”+
"" +
“SIPP-先生t测试”+
“BI830418”+
"83041" +
"" +
"23943" +
"2106175" +
“dffdf”+
“N14yKOOmpdmh23fmp7oNvg=”+
"0" +
“tz7r+uYFL6Ff86mI/mwJOQ=”+
“对”+
"" +
“对”+
"" +
"" +
"83041" +
"" +
"";
XElement-fatca=XElement.Parse(xml);
XNamespace ns=fatca.Name.Namespace;
字符串bankAccountNumber=fatca.subjects(ns+“bankAccountNumber”).FirstOrDefault()值;
}
}
}

您需要添加名称空间

归功于

var xmlReader=xmlReader.Create(新的StringReader(xml));//当然,不管你的消息来源是什么。
var myXDocument=XDocument.Load(xmlReader);
var namespaceManager=新的XmlNamespaceManager(xmlReader.NameTable);
namespaceManager.AddNamespace(“前缀”http://tempuri.org/TaskDetails.xsd"); // 我们为查询添加了一个显式前缀映射。
XElement-fatca=XElement.Parse(xml);
fatca.XPathSelectElement(//前缀:BankAccountNumber),namespaceManager.Value=“asd”;
Console.WriteLine(fatca.ToString());
​