所以我使用 PyXB 创建了 python 绑定,以便创建一个基于 xsd 模式的 xml 文件。
这是架构:
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2011 Nokia Siemens Networks
Permission to use, copy, modify, and distribute this software and its
documentation for any purpose, without fee, and without a written agreement
is hereby granted, provided that the above copyright notice and this
paragraph and the following two paragraphs appear in all copies.
IN NO EVENT SHALL COPYRIGHT HOLDERS BE LIABLE TO ANY PARTY FOR DIRECT,
INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST
PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
IF COPYRIGHT HOLDERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS,
AND COPYRIGHT HOLDERS HAVE NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,
UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
-->
<!-- ======================================================================= -->
<!-- XML DEFINITION FOR RAML 2.1 -->
<!-- Date: 08/06/2011 -->
<!-- @(#)MID: RAML21NX.XSD 1.1-0 12/10/24 -->
<!-- ======================================================================= -->
<xsd:schema
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:raml="raml21.xsd"
targetNamespace="raml21.xsd"
elementFormDefault="qualified"
attributeFormDefault="unqualified">
<!-- ============================= -->
<!-- ============================= -->
<!-- ============================= -->
<xsd:simpleType name="versions">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="2.1"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="planType">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="actual"/>
<xsd:enumeration value="plan"/>
<xsd:enumeration value="defaults"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="scopeType">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="all"/>
<xsd:enumeration value="hierarchy"/>
<xsd:enumeration value="changes"/>
<xsd:enumeration value="selection"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="operationType">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="create"/>
<xsd:enumeration value="update"/>
<xsd:enumeration value="delete"/>
<xsd:enumeration value="auto"/>
</xsd:restriction>
</xsd:simpleType>
<!-- ============================= -->
<!-- ============================= -->
<!-- ============================= -->
<xsd:element name="raml">
<xsd:annotation>
<xsd:documentation>RadioAccess Markup Language 2.1 definition</xsd:documentation>
</xsd:annotation>
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="raml:cmData" maxOccurs="unbounded"/>
</xsd:sequence>
<xsd:attribute name="version" type="raml:versions" use="required"/>
</xsd:complexType>
</xsd:element>
<!-- ============================= -->
<!-- ============================= -->
<!-- ============================= -->
<xsd:element name="cmData">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="raml:header"/>
<xsd:element ref="raml:managedObject" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
<xsd:attribute name="type" type="raml:planType" use="required"/>
<xsd:attribute name="scope" type="raml:scopeType" use="optional"/>
<xsd:attribute name="name" type="xsd:string" use="optional"/>
<xsd:attribute name="id" type="xsd:string" use="optional"/>
<xsd:attribute name="domain" type="xsd:string" use="optional"/>
<xsd:attribute name="adaptationVersionMajor" type="xsd:string" use="optional"/>
</xsd:complexType>
</xsd:element>
<!-- ============================= -->
<!-- ============================= -->
<!-- ============================= -->
<xsd:element name="header">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="raml:log" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<!-- ============================= -->
<!-- ============================= -->
<!-- ============================= -->
<xsd:element name="log">
<xsd:complexType>
<xsd:simpleContent>
<xsd:extension base="xsd:string">
<xsd:attribute name="dateTime" type="xsd:dateTime" use="required"/>
<xsd:attribute name="action" type="xsd:string" use="required"/>
<xsd:attribute name="user" type="xsd:string" use="optional"/>
<xsd:attribute name="appInfo" type="xsd:string" use="optional"/>
<xsd:attribute name="appVersion" type="xsd:string" use="optional"/>
<xsd:attribute name="adaptationVersionMinor" type="xsd:string" use="optional"/>
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>
</xsd:element>
<!-- ============================= -->
<!-- ============================= -->
<!-- ============================= -->
<xsd:element name="managedObject">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="raml:defaults" minOccurs="0"/>
<xsd:element ref="raml:extension" minOccurs="0" maxOccurs="unbounded"/>
<xsd:choice minOccurs="0" maxOccurs="unbounded">
<xsd:element ref="raml:p"/>
<xsd:element ref="raml:list"/>
</xsd:choice>
</xsd:sequence>
<xsd:attribute name="class" type="xsd:string" use="required"/>
<xsd:attribute name="version" type="xsd:string" use="optional"/>
<xsd:attribute name="operation" type="raml:operationType" use="optional"/>
<xsd:attribute name="distName" type="xsd:string" use="optional"/>
<xsd:attribute name="id" type="xsd:string" use="optional"/>
<xsd:attribute name="name" type="xsd:string" use="optional"/>
<xsd:attribute name="vendor" type="xsd:string" use="optional"/>
<xsd:attribute name="timeStamp" type="xsd:dateTime" use="optional"/>
</xsd:complexType>
</xsd:element>
<!-- ============================= -->
<!-- ============================= -->
<!-- ============================= -->
<xsd:element name="defaults">
<xsd:complexType>
<xsd:attribute name="name" type="xsd:string" use="required"/>
<xsd:attribute name="id" type="xsd:string" use="optional"/>
<xsd:attribute name="status" type="xsd:string" use="optional"/>
</xsd:complexType>
</xsd:element>
<!-- ============================= -->
<!-- ============================= -->
<!-- ============================= -->
<xsd:element name="extension">
<xsd:complexType>
<xsd:sequence>
<xsd:choice minOccurs="0" maxOccurs="unbounded">
<xsd:element ref="raml:p"/>
<xsd:element ref="raml:list"/>
</xsd:choice>
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="optional"/>
</xsd:complexType>
</xsd:element>
<!-- ============================= -->
<!-- ============================= -->
<!-- ============================= -->
<xsd:element name="p">
<xsd:complexType>
<xsd:simpleContent>
<xsd:extension base="xsd:string">
<xsd:attribute name="name" type="xsd:string" use="optional"/>
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>
</xsd:element>
<!-- ============================= -->
<!-- ============================= -->
<!-- ============================= -->
<xsd:element name="item">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="raml:p" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<!-- ============================= -->
<!-- ============================= -->
<!-- ============================= -->
<xsd:element name="list">
<xsd:complexType>
<xsd:choice>
<xsd:element ref="raml:p" minOccurs="0" maxOccurs="unbounded"/>
<xsd:element ref="raml:item" minOccurs="0" maxOccurs="unbounded"/>
</xsd:choice>
<xsd:attribute name="name" type="xsd:string" use="required"/>
</xsd:complexType>
</xsd:element>
<!-- ============================= -->
<!-- ============================= -->
<!-- ============================= -->
</xsd:schema>
我想做的是使用 pyxbgen 生成的模块创建一个 XML,但我不知道如何。pyxb 文档中的示例对我没有帮助。
我试图在这里发布模块,但它太大了。
谁能告诉我至少从哪里开始?
非常感谢!