Forum Moderators: coopster & phranque

Message Too Old, No Replies

XML Parsing

banging my head against the wall

         

volatilegx

2:48 am on Jun 8, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I've got a project that really has me banging my head against the wall. I'm writing an application that opens a socket to the UPS rates and services application that gives it the rates for the various services they offer for a particular package.

They serve this information in XML format. I'm having a hard time writing perl code that will parse the XML. I've been all over the documentatino for XML::Parser and XML::Simple but can't seem to come up with code that will work for me. Frankly, the modules are like "Greek to me".

Anybody have experience in this department?

volatilegx

5:09 am on Jun 8, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Looks like I cracked my current problem ;)

If anybody still wants to talk about parsing XML with perl, I'll discuss what I did...

Dan

ukgimp

8:33 am on Jun 8, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



is the xml well formed?

I had an example where I wanted to start launching my machine out the fifth floor window. I passed it onto a friend who came back with a load of expletives saying it was the worst usage of XML he had ever seen.

I still dont have a solotions so what did you do? :)

volatilegx

2:31 pm on Jun 8, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yeah, the XML was well formed, as far as I know -- I'm no XML expert.

What did I do? I taught myself how to use the XML::Parser perl module. There are loads of guides on the net about this module and similar modules, but none of them made sense to me. The module is very flexible and there are lots of "styles" you can use when implementing it. I wasn't sure which one to pick, and how to implement the one I picked. Finally, I found a good tutorial that I could halfway decifer...

[perlmonks.thepen.com...]

and from adaption of the example on that page, I came up with my solution.

I found that the trick was to use the default style "Tree", and assign my own custom subroutines to handle the the start of an element, the end of an element, and character text. After I figured that out, it was just a matter of untangling the mess of hashes that XML::Parser uses to keep the XML data in.

a1call

3:30 pm on Jun 9, 2004 (gmt 0)

10+ Year Member



Hi volatilegx,
I am in the same situation. Can you help.
I am offered xml feed from a ppc to incorporate in my perl driven site.
All I need is to parse the:
[domain.com...]
into a perl array.
What perl module should I use?
I made the example in the page that you refernced into a index.cgi. Uploaded and didn't run.
Help!
A few lines should do.

volatilegx

9:11 pm on Jun 9, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I might be able to help. The problem is, when you're parsing XML, you are looking for certain tags to parse, at least that's how I did it. I didn't bother to parse all the tags in the XML, only the ones I needed.

I couldn't tell what you were trying to do from your post. I guess I'd need more details.

If you're going to be parsing XML, then you should use the XML::Parser module, that's for sure.

IanKelley

12:16 am on Jun 12, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



a1call... When you're parsing an XML feed for a high traffic app like a search engine you are almost always better off writing your own code to parse the feed using regular expressions.

If well written this will end up being far more efficient than using an XML parser module and it will get around the fact that many search engine feeds display non-standard XML that will break any standard parser.