在php中计算xsd的元素

时间:2014-03-04 05:50:31

标签: php xsd

无论如何都要计算xsd中特定complextype元素中元素的数量。?

<xs:schema id="NewSchema" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="app_bundle_name" use="required" type="xs:string" fixed="com.smartgladiator.Link"/>
 <xs:element name="configuration_name" use="required" type="xs:string" />
      <xs:complexType name="connections1" minOccurs="1" maxOccurs="5" >
        <xs:sequence>
          <xs:element name="ip_address" type="xs:string" minOccurs="2" maxOccurs="5" />
          <xs:element name="port" type="xs:integer" minOccurs="2" maxOccurs="4" value="3">
                <xs:enumeration value="23"/>
                <xs:enumeration value="24"/>
                <xs:enumeration value="f1"/>
          </xs:element>
      </xs:sequence>
      </xs:complexType>
    </xs:schema>

如何在每个元素中找到枚举的数量?

1 个答案:

答案 0 :(得分:0)

尝试

$doc = new DOMDocument();
    $doc->loadXML($str);
    $seq =  $doc->getElementsByTagName('sequence');
    $elems =$seq->item(0)->getElementsByTagName('element');
    if($elems->length > 0 ){
     foreach($elems as $elem){
       if($elem->hasChildNodes()){
         $enums = $elem->getElementsByTagName('enumeration');
         foreach($enums as $enum){
           echo $enum->getAttribute('value');
         }
       }
     }
    }

请参阅演示here