XML/XML Schema/anyAttribute

Материал из Web эксперт
Перейти к: навигация, поиск

xsd:anyAttribute and processContents="lax": valid if a declaration exists

File: Data.xml
<?xml version="1.0"?>
<person xmlns="http://www.wbex.ru"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.wbex.ru Schema.xsd"
        id1="id1"
        id2="id2"
        id3="id3"
        id4="id4"
        >
 
  <firstname>
  </firstname>
  <lastname/>
</person>

File: Schema.xsd
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            targetNamespace="http://www.wbex.ru"
            xmlns="http://www.wbex.ru"
            elementFormDefault="qualified">
    <xsd:element name="person">
      <xsd:complexType>
        <xsd:sequence>
          <xsd:element name="firstname" type="xsd:string"/>
          <xsd:element name="lastname" type="xsd:string"/>
        </xsd:sequence>
        <xsd:anyAttribute processContents="lax"/>
      </xsd:complexType>
    </xsd:element>
</xsd:schema>



xsd:anyAttribute and processContents="skip": it only needs top be well-formed

File: Data.xml
<?xml version="1.0"?>
<person xmlns="http://www.wbex.ru"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.wbex.ru Schema.xsd"
        id1="id1"
        id2="id2"
        id3="id3"
        id4="id4"
        >
 
  <firstname>
  </firstname>
  <lastname/>
</person>

File: Schema.xsd
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            targetNamespace="http://www.wbex.ru"
            xmlns="http://www.wbex.ru"
            elementFormDefault="qualified">
    <xsd:element name="person">
      <xsd:complexType>
        <xsd:sequence>
          <xsd:element name="firstname" type="xsd:string"/>
          <xsd:element name="lastname" type="xsd:string"/>
        </xsd:sequence>
        <xsd:anyAttribute processContents="skip"/>
      </xsd:complexType>
    </xsd:element>
</xsd:schema>