Is it possible to add a new XML tag so that it's transparent for an XSD validation? -


a have xsd schema describes xml object (simplified example):

<xs:schema xmlns:xs="http://www.w3.org/2001/xmlschema"            targetnamespace="http://my-custom-ns.com">     <xs:element name="item">         <xs:complextype>             <xs:sequence>                 <xs:element name="active" type="xs:boolean"/>                 <xs:element name="value" type="xs:string"/>             </xs:sequence>         </xs:complextype>     </xs:element> </xs:schema> 

that schema built-in in app resource , installed on many workstations. app consumes xml files , validates them against schema. here (simplified) example of such xml:

<my:item xmlns:my="http://my-custom-ns.com">     <active>true</active>     <value>foo</value> </my:item> 

now, want xml files new element (a new tag) without changing xsd:

<my:item xmlns:my="http://my-custom-ns.com">     <active>true</active>     <value>foo</value>     <tag>bar</tag> </my:item> 

i'm not changing xsd, validation fails on new tag. there way having new tag in xml "passes through" validation transparently (i.e. gets ignored)?

i tried adding new namespace in xml in hope xsd validation ignore it, didn't help:

<my:item xmlns:my="http://my-custom-ns.com" xmlns:new="http://new-ns.com">     <active>true</active>     <value>foo</value>     <new:tag>bar</new:tag> </my:item> 

the background is: should possible current app version process xml files have additional tag, simple ignoring it. app has strong validation against xsd, described above. maybe there way this?

yes , no. there way achieve if original schema has special tag.

if know in advance documents may have elements, not know these elements in advance, schemas can designed in forward-compatible way using xs:any tags, so:

<xs:schema xmlns:xs="http://www.w3.org/2001/xmlschema"     targetnamespace="http://my-custom-ns.com">     <xs:element name="item">         <xs:complextype>             <xs:sequence>                 <xs:element name="active" type="xs:boolean"/>                 <xs:element name="value" type="xs:string"/>                 <xs:any namespace="##other" processcontents="lax" minoccurs="0"/>             </xs:sequence>         </xs:complextype>     </xs:element> </xs:schema> 

this document valid against above schema:

<my:item xmlns:my="http://my-custom-ns.com" xmlns:new="http://new-ns.com">     <active>true</active>     <value>foo</value> </my:item> 

as one:

<my:item xmlns:my="http://my-custom-ns.com" xmlns:new="http://new-ns.com">     <active>true</active>     <value>foo</value>     <new:tag>bar</new:tag> </my:item> 

the behavior of xs:any can adapted changing values of namespace , processcontents attributes.

however, if schema done, , outside of control, elements can appear if allowed original designer.

an example of is... xml schema itself. xml schema elements may contain arbitrary attributes in foreign namespaces (several standards built on xml schema way), , because xml schema of schemas explicitly allows attributes in other namespaces.


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -