XML Parsing

I want to parse some XML (downloaded from a URL into NSData) into an NSArray and am trying to use NSXMLDocument and NSXMLElement but can’t find the reference for them, so I’m getting unknown identifier.

Where are they? I saw XmlDocument and tried that, but can’t get to that either.

I thought there may be a sample for it since it’s got to be a common thing, but didn’t see one.

Define “can’t get to it”? I use Elements RTL’s XmlDocument for all my Xm ll needs, including in Fire, for ages. What problems are yo having, specifically?

I assume this is a Cocoa project? NSXMLDocument & co are in Foundation; XmlDocument (which I recommend to use) in in RemObjects.Elements.RTL, and needs a reference to Elements.fx (added by default, unless you unchecked the option)

That was it, thanks. I don’t seem to have had the libElements reference added, I don’t know why! It’s an app that I’ve had around for a log while. I’ve got foundation added but NSXMLDocument wasn’t showing at all.

I’ll use the XmlDocument one as you suggest, I see it looks simple to use! I assume it is something like this to get the document:

var url := RemObjects.Elements.RTL.Url.UrlWithString(‘https://myURL’);
var xmlDoc := RemObjects.Elements.RTL.XmlDocument.FromUrl(url);

I’ve actually got it working lovely from a file, so if the above doesn’t work I can download it then do it from a file.

that makes sense then. Personally, i’m so used to defaulting to use Elements RTL for everything, these days. Means less context switching between Cocoa and .NET :wink:

Curious. New app from template here finds it fine:

:raised_hands:

Yep, that’ll work. use TryFromUrl if you wanna get nil rather than an exception.

In general, the API is retry easy and time-proven. But if you have any feedback, let me know!

—marc

Mmm, not for me (iOS and Oxygene):

I also notice libElements isn’t present by default.

The parsing is so simple, I loved that! Worked perfectly.

I tried the URL bit, but got an error that says “Unexpected token. 3 is expected but 11 found at 1/1”

It must be something to do with the parameters as it fetched the base page perfectly well, so

https://WEBADDRESS

worked but

https://WEBADDRESS/export.php?ringer=John+Do

Did not. In fact, neither does https://WEBADDRESS/export.php (which does bring back an XML structure, albeit empty as I didn’t pass any parameters)

try doing a regular Http request to the same URL, and see what string you get back

Http.ExecuteRequestSynchronous(url).GetResponseAsStringSynchrnonous iirc.

I do get a string back, but not xml of course and though it’s readable I can’t do anything with it, and it’s not complete.

At least we known why the Xml parser doesn’t like it :wink:

Curious why it works fine in a browser directly though.

Indeed. can you show me WHAT you receive? Can you share the URL with me (in private)?

Thanks, sorted now. Had to add another query param to force the server to send it this way. Love the simplicity of TryFromUrl and then handle it.

1 Like