开发者

Is it possible to define XML schemata with node names specified via regular expressions?

开发者 https://www.devze.com 2022-12-28 14:59 出处:网络
I know it is probably a question against XML philosophy but still is it possible to define schemata for XML like this:

I know it is probably a question against XML philosophy but still is it possible to define schemata for XML like this:

<Root>
  <arbitrary-name-of-node>
   <Name></Name>
   <Position></Position>
   <!-- ... -->
  </arbitrary-n开发者_运维技巧ame-of-node>

  <arbitrary-name-of-node>
   <Name></Name> 
   <Position></Position>
   <!-- ... -->
  </arbitrary-name-of-node>
</Root>

where arbitrary-name-of-node matches regular expression [a-zA-Z0-9]?

Thanks for an answer!


I don´t think it´s possible.

The way I see it, you have two choices.

1. Create a schema like this, and add every "arbitrary-name-of-node" under the root type.

<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified"
 xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="Root">
    <xs:complexType>
      <xs:all>
        <xs:element name="arbitrary-name-of-node1" type="itemType" />
        <xs:element name="arbitrary-name-of-node2" type="itemType" />
        <xs:element name="arbitrary-name-of-node3" type="itemType" />
      </xs:all>
    </xs:complexType>
  </xs:element>
  <xs:complexType name="itemType">
    <xs:sequence>
      <xs:element name="Name" />
      <xs:element name="Position" />
      <!--...-->
    </xs:sequence>
  </xs:complexType>
</xs:schema>

2. Create a schema only for the content inside the "arbitrary-name-of-node" and validate each node by them selves.


  • http://www.xfront.com/VariableContentContainers.html#method1 - variable content containers are what I was looking for. My question was more general but this suffices my purposes.

  • http://www.w3schools.com/schema/schema_complex_any.asp

0

精彩评论

暂无评论...
验证码 换一张
取 消