Set XML element to no namespace in XSD? -
i'm trying validate xml according xsd. in xml there tags namespaces , without.
<my:person xmlns:my="http://my.namespace.com"> <my:name>john doe</my:name> <my:year>1988</my:year> <namespacelesselement>some value</namespacelesselement> </my:person>
my xsd looks this. validation fails because according xsd, namespacelesselement
has namespace.
<?xml version="1.0" encoding="utf-8" standalone="yes"?> <xs:schema xmlns:mynamespace="http://my.namespace.com" xmlns:xs="http://www.w3.org/2001/xmlschema" targetnamespace="http://my.namespace.com" elementformdefault="qualified"> <xs:element name="person" type="mynamespace:person"/> <xs:complextype name="person"> <xs:sequence> <xs:element name="name" type="xs:string"/> <xs:element name="year" type="xs:int"/> <xs:element name="namespacelesselement" type="xs:string"/> </xs:sequence> </xs:complextype> </xs:schema>
i can't find info on how turn off namespace namespacelesselement
. there way that?
all of components defined in xsd in namespace defined targetnamespace
. use xsd:import bring in xsd namespace different namespace:
main xsd
<?xml version="1.0" encoding="utf-8" standalone="yes"?> <xs:schema xmlns:mynamespace="http://my.namespace.com" xmlns:xs="http://www.w3.org/2001/xmlschema" targetnamespace="http://my.namespace.com" elementformdefault="qualified"> <xs:import schemalocation="namespacelesselement.xsd"/> <xs:element name="person" type="mynamespace:person"/> <xs:complextype name="person"> <xs:sequence> <xs:element name="name" type="xs:string"/> <xs:element name="year" type="xs:int"/> <xs:element ref="namespacelesselement"/> </xs:sequence> </xs:complextype> </xs:schema>
imported xsd
<?xml version="1.0" encoding="utf-8" standalone="yes"?> <xs:schema xmlns:xs="http://www.w3.org/2001/xmlschema" elementformdefault="qualified"> <xs:element name="namespacelesselement" type="xs:string"/> </xs:schema>
then xml,
<?xml version="1.0" encoding="utf-8"?> <my:person xmlns:my="http://my.namespace.com" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://my.namespace.com try.xsd"> <my:name>john doe</my:name> <my:year>1988</my:year> <namespacelesselement>some value</namespacelesselement> </my:person>
will validate requested.
Comments
Post a Comment