-1

I'm meeting a problem with an XPath request.

<mainNode id="id35" soapenc:root="0">
    <node1 xsi:type="soapenc:string">response1</node1>
    <node2 xsi:type="soapenc:string"/>
    <node3 xsi:type="soapenc:string">response2</node3>
    <node4 xsi:type="soapenc:string">response3</node4>
    <node5 href="#id156"/>
</mainNode>

My XPath Request :

/mainNode/node1/text()

The result :

ERROR - Seem like XML is not well formed:The prefix "soapenc" for attribute "soapenc:root" associated with an element type "mainNode" is not bound.

Any idea ?

PS : I get this XML File from a SOAP WebService

Ranpie49
  • 81
  • 2
  • 7
  • 1
    Is the example XML a full file? It seems that the `soapenc` namespace is not declared -- you should find `xmlns:soapenc="http://some.url/something`in it. – potame Apr 24 '15 at 08:26
  • I think you can also have a look at http://stackoverflow.com/questions/8745798/wsdl-type-soapencstring-cannot-be-resolved – potame Apr 24 '15 at 08:31

1 Answers1

0

It would be good to see a full sample XML, but it sounds like your issue is related to namespace management. You also do not specify which language you are using, but have you seen XML namespaces and XPath. The below is an exert from @harpo answer that shows how to strip namespaces from an XML doc if you really do not care about them.

"if you really need to perform XPath on documents that will use an unknown namespace, and you really don't care about it, you will need to strip it out and reload the document. XPath will not work in a namespace-agnostic way, unless you want to use the local-name() function at every point in your selectors."

private XmlDocument StripNamespace(XmlDocument doc)
{
    if (doc.DocumentElement.NamespaceURI.Length > 0)
    {
        doc.DocumentElement.SetAttribute("xmlns", "");
        // must serialize and reload for this to take effect
        XmlDocument newDoc = new XmlDocument();
        newDoc.LoadXml(doc.OuterXml);
        return newDoc;
    }
    else
    {
        return doc;
    }
}
Community
  • 1
  • 1
BMac
  • 2,183
  • 3
  • 22
  • 30
  • 1
    Why did you copy someone else's answer instead of referring to them or closing the question as a duplicate? Also, we do not know what programming language the OP uses and this C# excerpt might be utterly useless here. – Mathias Müller Apr 24 '15 at 08:55
  • @MathiasMüller I linked to the original question and answer, gave credit to Harpo's original answer. The reason for the quoted duplicate is to make sure future readers benefit in-case the original is removed from SO. I think you will find this is good practice if you read the FAQs. As I said in my answer the OP did not make his programming choice clear. – BMac Apr 24 '15 at 09:41
  • I do read a lot about what should be posted as a separate answer, and your post does certainly not qualify as an answer. If you are concerned about the the question you linked to being removed from Stackoverflow, why should a highly-upvoted answer be removed, but not this one here? That said, it's true that content from _elsewhere_ should be included in an SO answer for the reason you gave. How about extending your post to make it an answer in its own right? – Mathias Müller Apr 24 '15 at 14:19