xml - XSD: Validate a subnode based on its name and accept everything below -
in xml file, i've 1 specific node want present, not validate of content(sub-elements & attributes).
input xml
<?xml version="1.0" encoding="utf-8" ?> <rootcontainer xmlns="mynamespace"> <elementa/> <elementb/> <elementc/> <otherelement someattribute="value"> <subelementx/> <subelementy/> </otherelement> </rootcontainer>
xsd use validate
<?xml version="1.0" encoding="utf-8" ?> <xs:schema targetnamespace="mynamespace" elementformdefault="qualified" xmlns="mynamespace" xmlns:xs="http://www.w3.org/2001/xmlschema"> <xs:element name="rootcontainer"> <xs:complextype> <xs:sequence> <xs:element name ="elementa"/> <xs:element name ="elementb"/> <xs:element name ="elementc"/> <xs:element name="otherelement" minoccurs="0" maxoccurs="1" > <xs:complextype> <xs:sequence> <xs:any minoccurs="0" maxoccurs="unbounded" /> </xs:sequence> <xs:anyattribute/> </xs:complextype> </xs:element> </xs:sequence> </xs:complextype> </xs:element> </xs:schema>
but several errors (with .net, notepad++(with xml plugin) ): validation of current file using xml schema:
notepad++ errors:
error: element '{mynamespace}otherelement', attribute 'someattribute': no matching global attribute declaration available, demanded strict wildcard. error: element '{mynamespace}subelementx': no matching global element declaration available, demanded strict wildcard. error: element '{mynamespace}subelementy': no matching global element declaration available, demanded strict
.net errors:
the 'someattribute' attribute not declared. 'mynamespace:subelementx' element not declared. 'mynamespace:subelementy' element not declared.
so why? did misunderstood xs:any
, xs:anyattribute
?
you can use anytype that:
<xs:element name="otherelement" type="xs:anytype" minoccurs="0" maxoccurs="1" />
Comments
Post a Comment