[xml] Validating an xml doc against schema issue




Hi,

I'm having a problem validating an xml file against a schema, basically
it's with "substitutionGroup".

My schema is simple as following:

<?xml version="1.0" encoding="UTF-8"?>
   <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema";
              xmlns="http://myns";
              targetNamespace="http://myns";
              elementFormDefault="qualified"
              attributeFormDefault="unqualified">

     <xs:element name="rpcOperation" type="xs:string"/>

     <xs:complexType name="rpcType">
       <xs:sequence>
         <xs:element ref="rpcOperation"/>
       </xs:sequence>
     </xs:complexType>

     <xs:element name="rpc" type="rpcType"/>

     <xs:element name="get-config" substitutionGroup="rpcOperation"/>

   </xs:schema>

And my xml doc is even simpler:

<?xml version="1.0"?>
  <rpc xmlns="http://myns";>
    <get-config>hello</get-config>
  </rpc>

But after I've loaded the schema into memory and use it to validate the
xml file (by calling xmlSchemaValidateDoc), I get following error:

x.xml:3: element get-config: Schemas validity error : Element
'get-config': This element is not expected. Expected is (
{http://myns}rpcOperation ).

Element "get-config" is supposed to be the substitute of "rpcOperation",
so why does the call fail?

Thanks,
Yong Chen



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]