[Xml-compile] attribute and a child tag with the same name
Jozef Kutej
jozef at kutej.net
Fri Mar 27 07:44:34 GMT 2009
Hi,
on yesterdays ba.pm meeting I had a talk about how to use
XML::LibXML::Reader with XML::Compile::Schema to parse big XML files. As
I was showing XML::Compile::Schema I got a question what happens when
the parent tag attribute has the same name as child tag. Ex.:
<?xml version=3D"1.0"?>
<note to=3D"me">
<to>XML-Compile</to>
<from>ba.pm</from>
<heading>Reminder</heading>
<body>dont' forget</body>
</note>
In this case <note> has "to" attribute and <to> child tag at the same
time. I've tested it today and writer from:
{
'to' =3D> 'to',
'from' =3D> 'from',
'heading' =3D> 'head',
'body' =3D> 'b',
}
will produce:
<note><to>to</to><from>from</from><heading>head</heading><body>b</body></no=
te>
While reader when reading the example will generate this structure:
{
'body' =3D> 'dont\' forget',
'to' =3D> 'me',
'from' =3D> 'ba.pm',
'heading' =3D> 'Reminder'
}
of course neither writer nor reader can know which "to" (attribute or
element) I mean. On the other hand XML::Compile::Schema have the
possibility (unlike XML::Simple and friends) to find out from the schema
that there is a conflict and prefix the attribute name by _ or what
ever. What do you think?
Or what do you suggest for a documents like this? Write a hook?
Attached is a simple xsd+xml+pl that I used to play around with this.
Cheers,
Jozef
-------------- next part --------------
A non-text attachment was scrubbed...
Name: note-test.pl
Type: application/x-perl
Size: 1096 bytes
Desc: not available
Url : http://lists.scsys.co.uk/pipermail/xml-compile/attachments/20090327/d=
1f865cb/note-test.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: note.xml
Type: text/xml
Size: 139 bytes
Desc: not available
Url : http://lists.scsys.co.uk/pipermail/xml-compile/attachments/20090327/d=
1f865cb/note.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: note.xsd
Type: application/xml
Size: 478 bytes
Desc: not available
Url : http://lists.scsys.co.uk/pipermail/xml-compile/attachments/20090327/d=
1f865cb/note.xml
More information about the Xml-compile
mailing list