1

I'm trying to take an output from xml document using c#. But I don't receive any output to the grid and no error messages are generated. I assume this should be a mistake that i'm doing when using XmlnamespaceManager. I will show the coding that I'm using. Can somebody please help me to identify where am I going wrong. I have attached a sample xml file herewith. Thanks in advanceenter image description here

public void InitializePatchListArray()
{
    ArrayPatchList[0, 0] = "Installed Patch";
    ArrayPatchList[0, 1] = "/compositeReport/eisRecommendedPatchReport/@xmlns:ns2/ns2:recommendedPatchList/ns2:recommendedPatch/ns2:installedPatchId";
}

public void PopulatePatchList()
{
    XmlDocument XmlDoc = new XmlDocument();
    XmlDoc.Load(XMLFileLocation);

    for (int i = 0; i <6; i++)
    {
        XmlNamespaceManager manager = new XmlNamespaceManager(XmlDoc.NameTable);
        manager.AddNamespace("ns2", "http://webhome.central/xml/ns/bre/RuleService");
        XmlNodeList XmlValueList = XmlDoc.SelectNodes(ArrayPatchList[i, 1].ToString(),manager);              
    }
}
4

2 回答 2

2

很确定它只是你的 xpath - 奇怪的@xmlns:ns2看起来不合适。

public void InitializePatchListArray()
{
  ArrayPatchList[0, 0] = "Installed Patch";
  ArrayPatchList[0, 1] = "/compositeReport/eisRecommendedPatchReport/ns2:recommendedPatchList/ns2:recommendedPatch/ns2:installedPatchId";
}

应该可以正常工作。

于 2013-11-11T10:10:57.377 回答
0

我认为使用序列化可能更优雅和清晰。此外,如果您使用的是 Visual Studio 2012,您可以自动从 XML 创建一个类,然后在序列化或反序列化的地方,以简单的方式指向命名空间

于 2013-11-11T10:10:22.933 回答