需要PyXB帮助

2024-06-16 12:40:42 发布

您现在位置:Python中文网/ 问答频道 /正文

因此,我使用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文档中的示例对我没有帮助。在

我试着把模块贴在这里,但它太大了。在

有谁能告诉我至少从哪里开始?在

非常感谢!在


Tags: namerefstringvalueusetypeattributeelement
1条回答
网友
1楼 · 发布于 2024-06-16 12:40:42

我也有同样的问题。要下载源代码,请参考下面的示例。然后从主回购 转到./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目录查看演示。在

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

大卫先生

相关问题 更多 >