Delphi - Invalid namespace URI in IXMLNode

I am trying to parse a response from a SOAP web service, but some of the data has an invalid xmlns element, and I think this is not giving me any problems.

The piece of XML I'm working with looks like this.

<soap:Body xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <ResponseData xmlns="http://www.example.com/WebServices/Schemas/1">
        <ResponseDataResult>
            <Messages xmlns="http://www.example.com/WebServices/Schemas/2">
                <Message>...</Message>
            </Messages>
        </ResponseDataResult>
        ...
    </ResponseData>
</soap:Body>

      

Xmlns URI in soap: Body node ok, its value in ResponseData is invalid, it indicates no existing document. It should be noted that the web service is not under my control, so a fix for this is out of the question :(.

my Delphi (2007) code currently looks something like this.

var l_tmp,l_tmp2,FSOAPBody:IXMLNode;

begin
    ...

    FSOAPBody := FSOAPEnvelope.ChildNodes.FindNode('Body','http://schemas.xmlsoap.org/soap/envelope/');
    //returns the xml above.
    if (FSOAPBody = nil) then exit;

    l_tmp := FSOAPBody.ChildNodes.FindNode('ResponseData','');
    if (l_tmp = nil) or (not l_tmp.HasChildNodes) then exit;

    l_tmp2 := l_tmp.ChildNodes.FindNode('ResponseDataResult','');

    ...
end;

      

In the above code, I had to add an empty space FindNode('ResponseData','')

url to the -code, like outside of it, it won't find anything and will return null, but it will echo the expected XML.

The problem is that the following search for node ( ChildNodes.FindNode('ResponseDataResult','')

) causes an access violation when trying to access ChildNodes from l_tmp, I can look at the xml using l_tmp.xml and see that it is the XML I would expect.

I suspect it has something to do with the missing namespace, so I tried removing it, but getting more errors saying it is a read-only attribute.

Is there a way to remove the xmlns attribute or select nodes regardless of whether NS exists? or am I going about it wrong?

+1


a source to share


1 answer


All namespace URIs are not expected to refer to actual resources. They are used primarily as unique identifiers, so XML from multiple sources can use the same names without interfering with each other. They are not required to point to a schema that describes the valid element and attribute values ​​for the namespace; XML doesn't even require such a schema to exist.

If you want to search for elements without regard to namespace, then call the version with one argument FindNode

.

l_tmp := FSOAPBody.ChildNodes.FindNode('ResponseData');

      



The two-port version requires a namespace, and when you supply an empty string, it means you are only querying nodes with an empty namespace. Since you seem to know what a namespace is, you could name the two-argument version anyway, as you used it to get the body element:

l_tmp := FSOAPBody.ChildNodes.FindNode('ResponseData',
           'http://www.example.com/WebServices/Schemas/1');

      

+2


a source







All Articles