Jump to content

adding xml:lang to schema


Recommended Posts

I am trying to define a schema that includes xml:lang. I can add xml:lang to a dtd and it will pass xmllint, but I suspect I could add xml:foobar and it would pass xmllint.Please help me add xml:lang to both a dtd and schema. here is my test code:# pottmi@mikepb $ xmllint --schema myxmllang.xsd --noout myxmllang.xmlmyxmllang.xsd:14: element attribute: Schemas parser error : Attribute decl., attribute 'name' ['NCName']: The value 'xml:lang' is not valid.WXS schema myxmllang.xsd failed to compile# pottmi@mikepb $ xmllint --dtdvalid myxmllang.dtd --noout myxmllang.xml# pottmi@mikepb $ myxmllang.dtd: <!ELEMENT homepage (#PCDATA)> <!ATTLIST homepage xml:lang CDATA #REQUIRED> <!ELEMENT person (homepage)>myxmllang.xml:<?xml version="1.0"?><person><homepage xml:lang = "en" /></person><?xml version="1.0" ?><xs:schema xmlns:xs = "http://www.w3.org/2001/XMLSchema"> myxmllang.xsd <xs:element name="person"> <xs:complexType> <xs:sequence> <xs:element name="homepage" type="homepage"/> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="homepage"> <xs:complexType> <xs:attribute name="xml:lang" /> </xs:complexType> </xs:element></xs:schema>

Link to post
Share on other sites

The xml prefix is reserved for the XML namespace, which defines attributes standardized for XML parsers. This includes xml:lang, xml:base and xml:id. Implementations that don't recognize certain attributes ignore them as per specificaiton. You don't need to add anything to a schema to make those attributes valid. They already are and there's no way to make them invalid.

Link to post
Share on other sites
The xml prefix is reserved for the XML namespace, which defines attributes standardized for XML parsers. This includes xml:lang, xml:base and xml:id. Implementations that don't recognize certain attributes ignore them as per specificaiton. You don't need to add anything to a schema to make those attributes valid. They already are and there's no way to make them invalid.
I think what you are telling me that parsers do not have to enforce the xml: namespace being confined a limited number of keywords and that explains why xmllint allows xml:foobar to pass without an error.So what is wrong with my schema that it does not allow me to add an attribute xml:lang?I am sure it is something I am doing; I am relatively new to writing schemas.Mr. Potter
Link to post
Share on other sites

Yes. XML parsers do not enforce the XML namespace. That is why

<?xml version="1.0"?><element xml:lang="en"/>

is a well formed XML document, while

<?xml version="1.0"?><element w3:lang="en"/>

It's because XML parsers enforce all prefixes to be declared. The "xml" prefix however is predeclared and nodes in that namespace are part of the core language. Because of that, they don't need to be redeclared in schema.If you want to allow xml:lang, don't bother. It's already done. If you really need to use a custom attribute (for this or another purpose), use your own namespace. If you want to forbid them... don't bother. Just warn your users in a human readable way that your language doesn't interpret xml:lang and do not bother to create a handler for it.

Link to post
Share on other sites

Let me ask an explicite question:How do a modify this schema:

<?xml version="1.0" ?><xs:schema xmlns:xs = "http://www.w3.org/2001/XMLSchema">   <xs:element name="person">	<xs:complexType>	  <xs:sequence>		<xs:element name="homepage" type="homepage"/>	  </xs:sequence>	</xs:complexType>  </xs:element>  <xs:element name="homepage">	<xs:complexType>	  <xs:attribute name="xml:lang" />	</xs:complexType>  </xs:element></xs:schema>

Such that this xml is valid:

<?xml version="1.0"?><person><homepage xml:lang = "en" /></person>

This is the error that I get when I try to validate it:# pottmi@mikepb $ xmllint --schema myxmllang.xsd --noout myxmllang.xmlmyxmllang.xsd:14: element attribute: Schemas parser error : Attribute decl., attribute 'name' ['NCName']: The value 'xml:lang' is not valid.WXS schema myxmllang.xsd failed to compile-- Mr. Potter

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...