Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Odd XML parsing question #3

Closed
jeffbourassa opened this Issue Oct 3, 2011 · 4 comments

Comments

Projects
None yet
2 participants

HI

We are testing using this XML parser for a IOS project. Initial testing looked promising. However I have integrated this with our app build and am having issues.

If I use the feed coming from our server directly - the XML is setup like:

1A 2011-10-03 15:30:04 Not Available The cargo number entered … 13292-123456789 Port 813, PACIFIC HWY/SUR… 2011-10-03 15:30:04 1234567

This does not parse, regardless of where we put the document.root, etc.

If I trim the raw XML to:

    <RequestValidated>
      <Request>
        <cargonumber>1A</cargonumber>
        <requestdate>2011-10-03 15:30:04</requestdate>
        <returnStatus>Not Available</returnStatus>
        <returnInfo>The cargo number entered …</returnInfo>
        <transNo>13292-123456789</transNo>
        <portNo>Port 813, PACIFIC HWY/SUR…</portNo>
        <statusdate>2011-10-03 15:30:04</statusdate>
        <bacf>1234567</bacf>
      </Request>
    </RequestValidated>

I can get this to parse correctly. Am I missing something obvious here?

Here is the IOS code being used here:

// create a new SMXMLDocument with the contents of sample.xml
SMXMLDocument *document = [SMXMLDocument documentWithData:data error:NULL];

// Pull out the <Request> node
SMXMLElement *Requests = [document.root childNamed:@"Request"];

for (SMXMLElement *RequestResult in [Requests childrenNamed:@"Request"]) {

    NSString *CargoNumber = [RequestResult valueWithPath:@"cargonumber"]; // child node value
    NSString *requestdate = [RequestResult valueWithPath:@"requestdate"]; // child node value
NSString *returnStatus = [RequestResult valueWithPath:@"returnStatus"]; // child node value
    NSString *returnInfo = [RequestResult valueWithPath:@"returnInfo"]; // child node value
    NSString *transNo = [RequestResult valueWithPath:@"transNo"]; // child node value
    NSString *portNo = [RequestResult valueWithPath:@"portNo"]; // child node value
    NSString *statusdate = [RequestResult valueWithPath:@"statusdate"]; // child node value
    NSString *bacf = [RequestResult valueWithPath:@"bacf"]; // child node value

    NSLog(@"\n\n Status:\n CargoNumber: %@ \n returnStatus: %@ \n returnStatus: %@ \n returnInfo: %@ \n transNo: %@ \n portNo: %@ \n statusdate: %@ \n bacf: %@", CargoNumber, returnStatus, requestdate, returnInfo, transNo, portNo, statusdate, bacf);

Thanks

Jeff

Owner

nfarina commented Oct 3, 2011

Your document appears to contain an error. Try viewing it in a browser here:

http://f.cl.ly/items/0L3S333e3O3j3C1q2k0u/test.xml

You should see:

error on line 3 at column 47: Namespace prefix soapenv for encodingStyle on parsValidateResponse is not defined

You can also pass in an NSError instance to documentWithData to see the error in code.

NSError *error;
SMXMLDocument *document = [SMXMLDocument documentWithData:data error:&error];
NSLog(@"Error: %@", error);
<Envelope>
<Body>
    <parsValidateResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
        <parsValidateReturn xsi:type="ns2:Document">
            <RequestValidated>
                <Request1>
                    <cargonumber>1D</cargonumber>
                    <requestdate>2011-10-03 19:57:46</requestdate>
                    <returnStatus>Submitted</returnStatus>
                    <returnInfo>Entry is in progess, Cust…</returnInfo>
                    <transNo>13292-123456789</transNo>
                    <portNo>Port 813, PACIFIC HWY/SUR…</portNo>
                    <statusdate>2011-10-03 19:57:46</statusdate>
                    <bacf>1234567</bacf>
                </Request1>
            </RequestValidated>
        </parsValidateReturn>
    </parsValidateResponse>
</Body>
</Envelope>

Does not parse:

            <RequestValidated>
                <Request1>
                    <cargonumber>1D</cargonumber>
                    <requestdate>2011-10-03 19:57:46</requestdate>
                    <returnStatus>Submitted</returnStatus>
                    <returnInfo>Entry is in progess, Cust…</returnInfo>
                    <transNo>13292-123456789</transNo>
                    <portNo>Port 813, PACIFIC HWY/SUR…</portNo>
                    <statusdate>2011-10-03 19:57:46</statusdate>
                    <bacf>1234567</bacf>
                </Request1>
            </RequestValidated>

Does Parse correctly.

Question - why? Is there a workaround on the IOS side that could address this or are we best to look at the webservice.

This is rather perplexing.

Jeff

Possibly...

missing:

OTHER_LDFLAGS = -lxml2

HEADER_SEARCH_PATHS = /usr/include/libxml2

Owner

nfarina commented Oct 4, 2011

SMXMLDocument simply wraps NSXMLParser to decode the XML. In this case, NSXMLParser is throwing an error because it is unable to parse the document. I've demonstrated how to retrieve this error in my previous comment, and also how to validate your XML in Safari (which itself uses NSXMLParser).

I don't know much about XML namespaces personally so I'm afraid I can't help with your particular XML response. Best of luck!

@nfarina nfarina closed this Oct 4, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment