1

I have classes full of xpaths that now needs a specfic namespace. How can I accomplish this? What would be the easiest way to refactor this code? find replace?

What would be the best way to grab specific nodes in the future, if I don't know the namespaces ahead of time?

susr1 = root.SelectSingleNode("/PurchaseOrderRequest/DocumentHeader/DocumentInformation/DocumentIdentification/Type");

susr1 = root.SelectSingleNode("/PurchaseOrderRequest/ssdh:DocumentHeader/ssdh:DocumentInformation/ssdh:DocumentIdentification/ssdh:Type");

1 Answer 1

1

You can try this XML Library. Use XPathElement(). This is a .Net 3.5 solution if you can use it.

XElement root = XElement.Load(file) or .Parse(string)

Then either of your xpath's should work as long as there are not conflicting nodes with the same name (but different namespaces).

XElement susr1 = root.XPathElement("/PurchaseOrderRequest/DocumentHeader/DocumentInformation/DocumentIdentification/Type");

XElement susr1 = root.XPathElement("/PurchaseOrderRequest/ssdh:DocumentHeader/ssdh:DocumentInformation/ssdh:DocumentIdentification/ssdh:Type");

The library should figure out the namespace for you. I cannot test it without example xml to be sure.

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

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.