[xsd-users] Problem: About targetNamespace

杨开锦 email at yangkaijin.cn
Tue Apr 24 02:55:11 EDT 2018


I use the xsd.exe to generate xxx.hxx and xxx.cxx for my xxx.xsd

but when I try to parse the xml file, it failed with: no declaration found for element 'xxx'.


I try to locate the problem, and it seems to be that, my xxx.xsd has a targetNamespace declaration.


I take the situation into the Hello World Example:


xsd:


<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema_instance"
           targetNamespace="http://www.w3.org/2001/XMLSchema_instance"
           elementFormDefault="qualified" attributeFormDefault="unqualified">


  <xs:complexType name="hello_t">
    <xs:sequence>
      <xs:element name="greeting" type="xs:string"/>
      <xs:element name="name" type="xs:string" maxOccurs="unbounded"/>
    </xs:sequence>
  </xs:complexType>


  <xs:element name="hello" type="xsi:hello_t"/>


</xs:schema>



xml:


<?xml version="1.0"?>
<hello xmlns:xsi="http://www.w3.org/2001/XMLSchema_instance"
       xsi:noNamespaceSchemaLocation="hello.xsd">


  <greeting>Hello</greeting>


  <name>sun</name>
  <name>moon</name>
  <name>world</name>


</hello>





Then it does not work well, I need to known if there is some way to come through.


Note:
When I put the xsi prefix before the hello, greeting, name in the xml file, it stay still.
My xsd file comes from a third part, and it is long enough, so it would be large work to change all the declarations in the xsd file to kill the targetNamespace.


More information about the xsd-users mailing list