Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > XML::Simple oddity

Reply
Thread Tools

XML::Simple oddity

 
 
Rob
Guest
Posts: n/a
 
      02-15-2006
Hi,

I just found out that in my xml file, if I have one
ELEMENT with an ATTRIBUTE, the XML::Simple treats the
ATTRIBUTE as an ELEMENT....so:

<?xml version="1.0" standalone="no"?>
<!DOCTYPE site-catalog SYSTEM "xml_header.dtd">
<site-catalog>
<site>
<name>VNC</name>
<header>
<date id = "2006-01-04T23:14:23">
<fullname>UNKN </fullname>
<domes>NONE</domes>
<lat>UNKN</lat>
</date>
</header>
</site>
</site-catalog>

here, the DATA:umper prints:
$VAR1 = {
'site' => {
'name' => 'VNC',
'header' => {
'date' => {
'lat' => 'UNKN',
'domes' => 'NONE',
'id' => '2006-01-04T23:14:23',
'fullname' => 'UNKN ',
}
}
}
};



But, if I have 2 ELEMENTS w/ATTRIBUTES,

<?xml version="1.0" standalone="no"?>
<!DOCTYPE site-catalog SYSTEM "xml_header.dtd">
<site-catalog>
<site>
<name>VANCOUVER</name>
<header>
<date id = "2005-10-07T10:14:30">
<fullname>UNKN </fullname>
<domes>NONE</domes>
<lat>UNKN</lat>
</date>
<date id = "2006-01-04T23:14:23">
<fullname>UNKN </fullname>
<domes>NONE</domes>
<lat>UNKN</lat>
</date>
</header>
</site>
</site-catalog>

In this case, the DATA:umper prints:
$VAR1 = {
'site' => {
'name' => 'VANCOUVER',
'header' => {
'date' => {
'2005-10-07T10:14:30' => {
'lat' => 'UNKN',
'domes' => 'NONE',
'fullname' => 'UNKN',
},
'2006-01-04T23:14:23' => {
'lat' => 'UNKN',
'domes' => 'NONE',
'fullname' => 'UNKN'
}
}
}
}
};


How can I get the XML::Simple to print like the 2nd
case if I have the xml like the first case?
....thanx for any suggestions...


--Rob
 
Reply With Quote
 
 
 
 
J. Gleixner
Guest
Posts: n/a
 
      02-16-2006
Rob wrote:

> How can I get the XML::Simple to print like the 2nd
> case if I have the xml like the first case?
> ...thanx for any suggestions...


Start with the documentation.

perldoc XML::Simple

"ForceArray => 1 # in - important

This option should be set to '1' to force nested elements
to be represented as arrays even when there is only one.
...
"

 
Reply With Quote
 
 
 
 
Mahesh Asolkar
Guest
Posts: n/a
 
      02-16-2006
Rob wrote:
> Hi,
>
> I just found out that in my xml file, if I have one
> ELEMENT with an ATTRIBUTE, the XML::Simple treats the
> ATTRIBUTE as an ELEMENT....so:


.... snipped code and output

>
> How can I get the XML::Simple to print like the 2nd
> case if I have the xml like the first case?
> ...thanx for any suggestions...


I think what you are seeing is a result of the fact that XML::Simple
treats 'id' as a default KeyAttr. Please read the Note 1 in the
description of 'KeyAttr => [ list ] # in+out - important' at (or
perldoc):

http://search.cpan.org/~grantm/XML-S.../XML/Simple.pm

The documentation suggests that you set KeyAttr to an empty list if you
do not want 'id' to be treated as a KeyAttr.

HTH,
Mahesh.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
One More Wireless-to-Wired Oddity J Wireless Networking 1 01-02-2006 06:37 PM
pix policy nat small oddity Walter Roberson Cisco 0 07-12-2005 02:07 PM
PIX 501 PDM Oddity Hank Zoeller Cisco 2 05-20-2005 02:48 AM
803 password recovery oddity Cas Cisco 5 05-13-2005 09:41 AM
split commands oddity rxl124@hehe.com Perl 3 01-29-2004 07:59 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57