redcode
redcode

Reputation: 91

PyXB help needed

So I created python binding using PyXB in order to create a xml file based on a xsd schema.

Here is the schema:

<?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>

What I would like to do is to create a XML using the module produced by pyxbgen, but I have no idea how. The examples in pyxb docs did not help me.

I tried to post the module here, but it's just too big.

Can anyone give me an insight where to start at least?

Thank you very much!

Upvotes: 1

Views: 335

Answers (1)

david
david

Reputation: 87

I had the same problem. To download the source code please refer to the example below. Then from the main repo go to ./examples/manual/demo2.sh. I used git version PyXB-1.2.4.

example:

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

Then go to the .pyxb/examples/manual directory to look at the demos.

Let me know in the comments if you need more help.

BR David

Upvotes: 1

Related Questions