Languages and Scripting
Showing results for 
Search instead for 
Do you mean 

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

SOLVED
Go to Solution
Highlighted
Regular Advisor

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>
7 REPLIES
Honored Contributor

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
Honored Contributor

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
Regular Advisor

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
Honored Contributor

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






Honored Contributor

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
Regular Advisor

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.

Regular Advisor

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

Thanks!