XML::Simple doesn't handle shorthand notation?? (270 Views)
Reply
Regular Advisor
abc_18
Posts: 116
Registered: ‎06-26-2004
Message 1 of 8 (270 Views)
Accepted Solution

XML::Simple doesn't handle </tag> shorthand notation??

What's the trick to getting XML::Simple to handle
an empty closing tag. Ie supposedly this XML fragment



can be written with the shorthand:


However XML::Simple gags with a "mismatched tag" (details appended).
Any ideas?

Thanks in advance!
-Ted

---- cut here for demo ----
alps(ted) 743>cat dumpit.pl
#!/opt/perl/bin/perl

# use module
# create object
$xml = new XML::Simple;

# read XML file
$data = $xml->XMLin("./$ARGV[0]");

# print output
print Dumper($data);



alps(ted) 746>dumpit.pl fkd.up.xml

mismatched tag at line 3, column 10, byte 56 at /opt/perl/lib/site_perl/5.6.1/PA
-RISC1.1-thread-multi/XML/Parser.pm line 168
alps(ted) 747>
Please use plain text.
Honored Contributor
Peter Godron
Posts: 4,470
Registered: ‎02-13-2002
Message 2 of 8 (270 Views)

Re: XML::Simple doesn't handle </tag> shorthand notation??

Hi,
If nested, XML elements must be strictly nested: each start tag must have a corresponding end tag, and elements cannot overlap.

XML's shorthand for an empty element (that is, one without contents), is ending the tag with a "/>".

Regards
Please use plain text.
Honored Contributor
Ralph Grothe
Posts: 2,631
Registered: ‎04-09-2000
Message 3 of 8 (270 Views)

Re: XML::Simple doesn't handle </tag> shorthand notation??

I'd like to know how you got XML::Parser installed in case you didn't use any with gcc prebuilt binaries.

I experience tremendous difficulties getting XML::Parser's XS stubs linked against the libexpat.sl
But see my thread

http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=791021
Madness, thy name is system administration
Please use plain text.
Regular Advisor
abc_18
Posts: 116
Registered: ‎06-26-2004
Message 4 of 8 (270 Views)

Re: XML::Simple doesn't handle </tag> shorthand notation??

I gave out low points because my question is
still open. Perhaps it was oddly worded.
So I'll rephrase the question.

Q: Is there any option/trick/magic potion which will enable XML::Simple to parse this XML document:

alps(ted) 747>cat ugly.xml




alps(ted) 748>

without dying with an "unmatched tag" error??

If not, can I use XML::DOM or XML::XPath to parse it? (Sample code appreciated).

----
To answer the other question, I'm using a
pre-built perl which apparently is distributed with HP-UX standard now. It's built by ActiveState and lives in /opt/perl/bi/perl.

alps(ted) 751>/opt/perl/bin/perl -v
This is perl, v5.6.1 built for PA-RISC1.1-
Copyright 1987-2001, Larry Wall
Binary build 627 provided by ActiveState Tool Corp. http://www.ActiveState.com
Built 21:42:53 Jun 20 2001
Please use plain text.
Honored Contributor
Stephen Keane
Posts: 1,155
Registered: ‎11-24-2004
Message 5 of 8 (270 Views)

Re: XML::Simple doesn't handle </tag> shorthand notation??

As Peter stated, you are trying to get an XML parser to parse code that doesn't meet the XML standard!

You code should read






Please use plain text.
Honored Contributor
Peter Godron
Posts: 4,470
Registered: ‎02-13-2002
Message 6 of 8 (270 Views)

Re: XML::Simple doesn't handle </tag> shorthand notation??

Hi,
look like a definite:

http://www.perldoc.com/perl5.6.1/lib/XML/Simple.html#ERROR-HANDLING

states
"The XML standard is very clear on the issue of non-compliant documents. An error in parsing any single element (for example a missing end tag) must cause the whole document to be rejected. XML::Simple will die with an appropriate message if it encounters a parsing error."

Sorry
Please use plain text.
Regular Advisor
abc_18
Posts: 116
Registered: ‎06-26-2004
Message 7 of 8 (270 Views)

Re: XML::Simple doesn't handle </tag> shorthand notation??

Thanks, I get it now.
I'd thought the spec for an empty element
was to leave off the opening element.

I didn't realize (until Stepen so nicely
spelled it out) that the really syntax
is to have a bizarro element, where the
"/" is moved to the end of the element
instead of the FRONT of it.

Please use plain text.
Regular Advisor
abc_18
Posts: 116
Registered: ‎06-26-2004
Message 8 of 8 (270 Views)

Re: XML::Simple doesn't handle </tag> shorthand notation??

Thanks!
Please use plain text.
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation