[Xml-compile] Unexpected elements and attributes

Mark Overmeer mark at overmeer.net
Wed Apr 14 22:04:14 GMT 2010


* John Hayden (john.hayden at analog.com) [100414 18:57]:
> I don't think I should have to declare elements or attributes as "prohibited";

Well, actually don't try to think: your brain will hurt when you try to
understand the designers of schemas.  Elements and attributes are quite
different. Elements are only allowed when you specify them explicitly
(or "any"). Attributes are always permitted, but only understood when
you specify them. It's designed that way.

> I think if they're not in the schema they should be prohibited by default.
> But the reader in this example does not complain about badAttr or the element
> <bad>; it simply drops it from the data it returns.

Your example is flawed: the "bottom" is declared as string and interpreted
as string.  That means that <bad> is not an element but simply part
of the string.

In the implementation, XML::Compile bluntly takes the $node->textContent
when it needs the string value. However, it may be needed to check for
childs. I do not know what the spec says about it. Anyway: XML::Compile
takes the simplest take for the moment until proven wrong.

> ... but when I move the attribute line above the sequence as shown here,
> the schema gives an error message (when compiling the reader):
> 
> <?xml version="1.0" encoding="utf-8"?>
> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
>   <xsd:element name="top">
>     <xsd:complexType>
>       <xsd:attribute name="goodAttr"  type="xsd:string"/>
>       <xsd:sequence>
>         <xsd:element name="bottom" type="xsd:string"/>
>       </xsd:sequence>
>      </xsd:complexType>
>   </xsd:element>
> </xsd:schema>
> 
> => error: trailing non-attribute `sequence' at top

Yes, it is a violation of the schema schema.  It's just designed that
way. Welcome to my world ;-)  Don't worry, you will tear more hairs
when you see the rest of it.
-- 
Regards,
               MarkOv

------------------------------------------------------------------------
       Mark Overmeer MSc                                MARKOV Solutions
       Mark at Overmeer.net                          solutions at overmeer.net
http://Mark.Overmeer.net                   http://solutions.overmeer.net




More information about the Xml-compile mailing list