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);              
    }
}
2
  • Does it work if you don't have the /@xmlns:ns2 section in your path expression? I'm not clear on what you were trying to do with that portion. Commented Nov 11, 2013 at 10:04
  • why are you creating the namespace manager inside the loop Commented Nov 11, 2013 at 10:08

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Yes that was the issue. Thanks alot
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.