RobinR
10-01-2004, 04:25 PM
When you receive an XML response back and there might be a node with a particular name but there may not be, how do you handle that? Also, when a node has no child nodes, what is the best way to obtain the data in it?
In the sample response from Fedex, I’d like to:
- get the Meter Number
- get the attribute in SubscribedService
- find out if there is an error if the request is invalid
It should be simple but I’m having difficulty with it. Also, according to my UPS documentation, you should be able to find out if a node exists with the following code. However, I get an “object required” error message when trying to use it:
<%
Set xmlDoc = Server.CreateObject(“MSXML.DOMDocument”)
XmlDoc.validateonParse = False
XmlDoc.loadXML(xmlStr)
If xmlDoc.documentElement.nodeName = “Error” Then
…
End If
%>
I would like to use the XML DOM to extract the response text.
Thanks for your help,
Robin
*************************************************************
Fedex Response Example 1 (Valid Request):
<?xml version="1.0" encoding="UTF-8"?>
<FDXSubscriptionReply xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FDXSubscriptionReply.xsd">
<RequestHeader>
<CustomererTransactionIdentifier>String</CustomerTransactionIdentifier>
</RequestHeader>
<MeterNumber>1234567</MeterNumber>
<SubscribedService>
<SubscribedService Name="FedEx ExpressShipping" />
</SubscribedService>
</FDXSubscriptionReply>
**********************************************************
Fedex Response Example 2 (Error):
<?xml version="1.0" encoding="UTF-8"?>
<FDXSubscriptionReply xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FDXSubscriptionReply.xsd">
<RequestHeader>
<CustomererTransactionIdentifier>String</CustomerTransactionIdentifier>
</RequestHeader>
<Error>
<Code>20528</Code>
<Message>Invalid Zip Code</Message>
</Error>
</FDXSubscriptionReply>
In the sample response from Fedex, I’d like to:
- get the Meter Number
- get the attribute in SubscribedService
- find out if there is an error if the request is invalid
It should be simple but I’m having difficulty with it. Also, according to my UPS documentation, you should be able to find out if a node exists with the following code. However, I get an “object required” error message when trying to use it:
<%
Set xmlDoc = Server.CreateObject(“MSXML.DOMDocument”)
XmlDoc.validateonParse = False
XmlDoc.loadXML(xmlStr)
If xmlDoc.documentElement.nodeName = “Error” Then
…
End If
%>
I would like to use the XML DOM to extract the response text.
Thanks for your help,
Robin
*************************************************************
Fedex Response Example 1 (Valid Request):
<?xml version="1.0" encoding="UTF-8"?>
<FDXSubscriptionReply xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FDXSubscriptionReply.xsd">
<RequestHeader>
<CustomererTransactionIdentifier>String</CustomerTransactionIdentifier>
</RequestHeader>
<MeterNumber>1234567</MeterNumber>
<SubscribedService>
<SubscribedService Name="FedEx ExpressShipping" />
</SubscribedService>
</FDXSubscriptionReply>
**********************************************************
Fedex Response Example 2 (Error):
<?xml version="1.0" encoding="UTF-8"?>
<FDXSubscriptionReply xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FDXSubscriptionReply.xsd">
<RequestHeader>
<CustomererTransactionIdentifier>String</CustomerTransactionIdentifier>
</RequestHeader>
<Error>
<Code>20528</Code>
<Message>Invalid Zip Code</Message>
</Error>
</FDXSubscriptionReply>