需要PyXB帮助

时间:2015-09-29 01:56:03

标签: python xml xsd pyxb

所以我使用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文档中的示例对我没有帮助。

我试图在这里发布模块,但它太大了。

任何人都可以告诉我至少从哪里开始?

非常感谢!

1 个答案:

答案 0 :(得分:1)

我遇到了同样的问题。要下载源代码,请参阅下面的示例。然后从主回购 转到./examples/manual/demo2.sh。我使用了git版本PyXB-1.2.4。

示例:

cd to some_dir
git clone https://github.com/pabigot/pyxb.git
git checkout PyXB-1.2.4.

然后转到.pyxb / examples / manual目录查看演示。

如果您需要更多帮助,请在评论中告诉我。

BR大卫