Найти - Пользователи
Полная версия: xml schema
Начало » Python для новичков » xml schema
1
SHDW
1. есть xml schema
 <!--  Header 
-->
+ <xs:simpleType name="RelationRoleType">
- <xs:annotation>
<xs:documentation>The role of a relation between related resources.</xs:documentation>
</xs:annotation>
- <xs:restriction base="xs:string">
<xs:enumeration value="IsVersionOf" />
<xs:enumeration value="HasVersion" />
<xs:enumeration value="IsReplacedBy" />
<xs:enumeration value="Replaces" />
</xs:restriction>
</xs:simpleType>
+ <xs:complexType name="RelationType">
- <xs:annotation>
<xs:documentation>A reference to a related resource. Four roles are defined for now: IsVersionOf means that the current resource has been derived from the other resource. IsReplacedBy means that the current resource is now obsolete and should be replaced by the other resource. HasVersion and Replaces are respectively the opposites of IsVersionOf and IsReplacedBy</xs:documentation>
</xs:annotation>
<xs:attribute name="role" type="RelationRoleType" />
<xs:attribute name="resource" type="xs:string" />
</xs:complexType>
+ <xs:complexType name="HeaderType">
- <xs:annotation>
<xs:documentation>A collection of metadata relative to the file (author, date, title, ...)</xs:documentation>
</xs:annotation>
- <xs:sequence>
- <xs:element name="SchemaVersion" type="xs:decimal" fixed="4.3">
- <xs:annotation>
<xs:documentation>The version of 3dxml generic schema on which the file is based.</xs:documentation>
</xs:annotation>
</xs:element>
- <xs:element name="Title" type="xs:string" minOccurs="0">
- <xs:annotation>
<xs:documentation>A name given to the file. Should be explicit enough to define a name by which the file can be formally known.</xs:documentation>
</xs:annotation>
</xs:element>
- <xs:element name="Description" type="xs:string" minOccurs="0">
- <xs:annotation>
<xs:documentation>Abstract, table of contents or free text. A description should give an insight of what is contained in the file and what it is used for. This field should be limited to a few lines.</xs:documentation>
</xs:annotation>
</xs:element>
- <xs:element name="Subject" type="xs:string" minOccurs="0">
- <xs:annotation>
<xs:documentation>The topic of the content of the file chosen from a classification system.</xs:documentation>
</xs:annotation>
</xs:element>
- <xs:element name="Source" type="xs:string" minOccurs="0">
- <xs:annotation>
<xs:documentation>A Reference to a resource from which the present file is derived.</xs:documentation>
</xs:annotation>
</xs:element>
- <xs:element name="Author" type="xs:string" minOccurs="0">
- <xs:annotation>
<xs:documentation>An entity (a person, an organization, or a service) primarily responsible for making the content of the resource.</xs:documentation>
</xs:annotation>
</xs:element>
- <xs:element name="Contributor" type="xs:string" minOccurs="0">
- <xs:annotation>
<xs:documentation>An entity (a person, an organization, or a service) responsible for making contributions to the content of the resource.</xs:documentation>
</xs:annotation>
</xs:element>
- <xs:element name="Generator" type="xs:string" minOccurs="0">
- <xs:annotation>
<xs:documentation>Name and version of the software used to generate the file.</xs:documentation>
</xs:annotation>
</xs:element>
- <xs:element name="Rights" type="xs:string" minOccurs="0">
- <xs:annotation>
<xs:documentation>Information about rights held in and over the resource (includes copyright, Intellectual Property Rights,...).</xs:documentation>
</xs:annotation>
</xs:element>
- <xs:element name="Created" type="xs:date" minOccurs="0">
- <xs:annotation>
<xs:documentation>A date associated with the creation of the resource (ISO 8601 YYYY-MM-DD format)</xs:documentation>
</xs:annotation>
</xs:element>
- <xs:element name="Modified" type="xs:date" minOccurs="0">
- <xs:annotation>
<xs:documentation>A date associated with the last modification of the resource (ISO 8601 YYYY-MM-DD format)</xs:documentation>
</xs:annotation>
</xs:element>
- <xs:element name="Issued" type="xs:date" minOccurs="0">
- <xs:annotation>
<xs:documentation>A date associated with the publication of the resource (ISO 8601 YYYY-MM-DD format)</xs:documentation>
</xs:annotation>
</xs:element>
- <xs:element name="Identifier" type="UUIDType" minOccurs="0">
- <xs:annotation>
<xs:documentation>An unambiguous reference to the resource within a given context.</xs:documentation>
</xs:annotation>
</xs:element>
- <xs:element name="Language" type="xs:language" minOccurs="0">
- <xs:annotation>
<xs:documentation>The language of the intellectual content of the file.</xs:documentation>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:complexType>
- <!-- Header
-->
2. есть xml документ как образец.
- <Header>
<SchemaVersion>4.3</SchemaVersion>
<Title>Quad File</Title>
<Author>PVO</Author>
<Generator>Prog</Generator>
<Created>2007-04-19</Created>
</Header>
3. и маленькая дока
http://s04.radikal.ru/i177/1111/73/88615aeb61fe.png

тк я только начинаю осваивать возникает вопрос:
1.есть ли инструмент в python для создания xml файла согласно схеме
2.достаточно ли будет( и стоит ли смотреть)lxml?
быстродействие в данном случае на втором месте.
3.в будущем планируется редактирование полученного xml
4.и вообще посоветуйте с чего начать:)
PooH
Ну а в чем проблема то? Смотрите в схему и генерируйте документ, хоть через lxml, хоть текстом. Потом можете наложить схему на полученный документ для проверки:
# encoding: utf-8
from lxml import etree

scheme = etree.XMLSchema(etree.parse('scheme.xsd'))
doc = etree.parse('document.xml')

if not scheme(doc):
print u'Ничего не получилось :('
SHDW
проблема в том, что исходные данные- неупорядоченный набор строк, преимущественно текст, а не xml
PooH
SHDW
проблема в том, что исходные данные- неупорядоченный набор строк, преимущественно текст, а не xml
Ну тогда вы не тот или неполный вопрос задали. Давайте показывайте что на входе.
SHDW
на входе есть данные,схема краткий мануал.
необходимо создать новый xml документ по этим данным
cutwater
SHDW
на входе есть данные,схема краткий мануал.
необходимо создать новый xml документ по этим данным
Ручками сэр, ручками.
Вы не понимаете назначение XML Schema. Она служит для валидации уже готового XML, а не для построения на ее основе XML из каких-либо данных
SHDW
а…. ну с этого и надо было начинать)
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB