XML namespaces in (pure) perl parsers?

B

bugbear

I need to do some fairly simple processing
of XML files; I would like to be able to do this
in perl.

However, the XML I'm handling uses namespaces.

In practice, the tags do not overlap,
so I could achieve the functionality I need
by simply stripping namespace information.

Question: what XML parsers, callable from perl
support namespaces (either properly, or by
carefully ignoring them)?

And, of these, which (if any) of them do not require
compilation to install (i.e. which are "pure" perl).

The reason for the latter restriction is ease
of installation on some nasty, obscure, old
hardware (don't ask, you DON'T want to know ;-)

BugBear
 
J

Joe Kesselman

I don't use perl, so I can't recommend specific packages, but any modern
XML parser *should* support namespaces...
 
B

bugbear

Joe said:
I don't use perl, so I can't recommend specific packages, but any modern
XML parser *should* support namespaces...

You're right, and yet wrong. Many modern perl parsers don't.

Hence my question.

BugBear
 
J

Joseph Kesselman

bugbear said:
You're right, and yet wrong. Many modern perl parsers don't.

OK, we can quibble about whether they can claim to be "modern" in that
case as opposed to just "obsolete but still in use" (<sigh/>)...

Unfortuately I don't know the perl toolspace, so I can't offer opinions
on which ones you should be switching to; I'd have to start with a
websearch, and you can do that just about as effectively yourself.

Hopefully someone else can point you in the right direction.
 
B

Bart Van der Donck

bugbear said:
I need to do some fairly simple processing
of XML files; I would like to be able to do this
in perl.

However, the XML I'm handling uses namespaces.

In practice, the tags do not overlap,
so I could achieve the functionality I need
by simply stripping namespace information.

Yes, quite possible, and a common strategy for this kind of stuff.
Question: what XML parsers, callable from perl
support namespaces (either properly, or by
carefully ignoring them)?

You can find a bunch of modules on CPAN that handle XML namespaces,
see.e.g.
http://cpan.uwinnipeg.ca/search?query=xml+namespace
And, of these, which (if any) of them do not require
compilation to install (i.e. which are "pure" perl).

'XML::NamespaceSupport' and 'XML::Writer' are available by default on
my FreeBSD machine with perl v5.8.3.
The reason for the latter restriction is ease
of installation on some nasty, obscure, old
hardware (don't ask, you DON'T want to know ;-)

Well, maybe you have nasty, obscure, old hardware but with the latest
perl version on it :)

As a general rule, the older an XML module, the less chance it will
support namespaces.

Summarized, there are two possible solutions for your problem:
(1) use a module
or
(2) regexp out the colons (only inside XML tags) and regexp them back
after parsing
 
J

Jim Gibson

bugbear said:
I need to do some fairly simple processing
of XML files; I would like to be able to do this
in perl.

However, the XML I'm handling uses namespaces.

In practice, the tags do not overlap,
so I could achieve the functionality I need
by simply stripping namespace information.

Question: what XML parsers, callable from perl
support namespaces (either properly, or by
carefully ignoring them)?

And, of these, which (if any) of them do not require
compilation to install (i.e. which are "pure" perl).

The reason for the latter restriction is ease
of installation on some nasty, obscure, old
hardware (don't ask, you DON'T want to know ;-)

There is XML::SAX::purePerl, which is slow, and I do not know if it
handles namespaces. According to its documentation, XML::SAX will use
XML::SAX::purePerl if nothing else if available, and XML::Simple will
use XML::SAX for a parser if XML::parser is not available. Confusing,
no?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top