Reputation: 153
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 advance
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);
}
}
Upvotes: 1
Views: 133
Reputation: 1064044
Pretty sure it is just your xpath - the odd @xmlns:ns2
looks out of place.
public void InitializePatchListArray()
{
ArrayPatchList[0, 0] = "Installed Patch";
ArrayPatchList[0, 1] = "/compositeReport/eisRecommendedPatchReport/ns2:recommendedPatchList/ns2:recommendedPatch/ns2:installedPatchId";
}
should work fine.
Upvotes: 2
Reputation:
I think that using serialization may be more elegant and clear. Moreover, if you're using Visual Studio 2012, you can create a class from XML automatically and then, where serializing or deserializing, point the namespaces in a simple way
Upvotes: 0