Altova Mailing List Archives>Archive Index >microsoft.public.xml Archive Home >Recent entries >Thread Prev - Can this be done in XSD? >Thread Next - Re: Can this be done in XSD? Re: Can this be done in XSD?To: NULL Date: 11/1/2004 6:51:00 PM
Sven Groot wrote:
> I have the following XML document.
>
> <foo:Bar xmlns:foo="urn:foo-namespace">
> <SomeElt foo:id="test" foo:someparam="bar" someotherparam="someothervalue"
> />
> </foo:Bar>
>
> I want to create a schema for the foo namespace. The Bar element should be
> able to contain any element without a namespace. This is easily accomplished
> by using <xs:any namespace="##local" processContents="skip" />
>
> However, as you can see, these elements do contain attributes from the foo
> namespace. Is it possible to have these attributes validated. For instance
> if foo:someparam is a simpleType enumeration that allows only the values
> "foo" and "foo2", how would I have it trigger a schema exception on the
> above document? What do I need to write in my XSD to make it validate those
> attributes. Obviously processContents="skip" is wrong, but "lax" has the
> same results.
>
> Is there any way this can be done, and if so, how?
Using processContents="lax" I think that at least Xerces-J then tries to
validate the attributes and flags any errors.
I have used the following schema to test that:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://example.com/2004/11/01/foo"
elementFormDefault="qualified"
attributeFormDefault="qualified"
version="1.0">
<xs:element name="element">
<xs:complexType>
<xs:sequence>
<xs:any namespace="##local" processContents="lax" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:attribute name="enum">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="Kibo" />
<xs:enumeration value="Xibo" />
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:schema>
then the following instance
<?xml version="1.0" encoding="UTF-8"?>
<foo:element xmlns:foo="http://example.com/2004/11/01/foo"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://example.com/2004/11/01/foo
test2004110101Xsd.xml">
<some-element foo:enum="Maho" />
</foo:element>
and then Xerces-J as available with the JEdit XML plugin flags the error
test2004110102.xml:5:cvc-enumeration-valid: Value 'Maho' is not
facet-valid with respect to enumeration '[Kibo, Xibo]'.
thus at least that processor does validate the attributes.
Trying the same with MSXML 5 however doesn't flag any errors.
I am not sure what the XML schema specifiation requires in that case.
--
Martin Honnen
http://JavaScript.FAQTs.com/
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
