How to modify XSD element from string to xml?

北战南征 提交于 2019-12-24 11:37:27

问题


I have the following part in my XSD:

 <xs:element name="Parameter">
   <xs:complexType mixed="true">
     <xs:attribute name="Name" use="required" type="xs:string"/>
   </xs:complexType>
 </xs:element>

which means that value for a Parameter can be any string. Can I somehow specify that value for Parameter can be any valid xml like <aaa></aaa> ? Something like type="xs:xml"


回答1:


You will have to use

<xs:element name="Parameter" type="myType>

where

<complexType name="myType>
<choice>
<element "myXml" type="xml">
<element "myStr" type="xs:sting">
</choice>
</complexType>

and you will have to define xml like a pattern of xml you want to be your value.




回答2:


Use <xs:any> to allow any XML elements in your content model.

<xs:element name="Parameter">
  <xs:complexType>
    <xs:sequence>
      <xs:any minOccurs="0" maxOccurs="unbounded"/>
    </xs:sequence>
  </xs:complexType>
</xs:element>

You can restrict elements allowed by <xs:any> to certain namespaces with namespace attribute and control their validation with processContents attribute. To allow any attribute, use <xs:anyAttribute>

More info in the XML Schema recommendation: 3.10.2 XML Representation of Wildcard Schema Components



来源:https://stackoverflow.com/questions/6136934/how-to-modify-xsd-element-from-string-to-xml

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!