以下Q的高额奖金:
您好,这是我在Ubuntu 9.10上使用Python 2.6,Amara2尝试的(顺便说一句,test.xsd是使用xml2xsd工具创建的):
g@spot:~$ cat test.xml; echo =====o=====; cat test.xsd; echo ====
o=====; cat test.py; echo =====o=====; ./test.py; echo =====o=====
<?xml version="1.0" encoding="utf-8"?>==; ./test.py` >
test.txttest.xsd; echo ===
<test>abcde</test>
=====o=====
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
<xs:element name="test" type="xs:NCName"/>
</xs:schema>
=====o=====
#!/usr/bin/python2.6
# I wish to validate an xml file against an external XSD schema.
from amara import bindery, parse
source = 'test.xml'
schema = 'test.xsd'
#help(bindery.parse)
#doc = bindery.parse(source, uri=schema, validate=True) # These 2 seem
to fail in …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用python-amara解析xml文件.
doc = amara.parse('h.xml')
assert doc.xml_type == tree.entity.xml_type
m = doc.xml_children[0]
print m
Run Code Online (Sandbox Code Playgroud)
当我这样做时,它给出了
amara.tree.element at 0x94c864c: name u'HOP', 0 namespaces, 0 attributes, 93 children
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试这个:
print doc.HOP.A.D
Run Code Online (Sandbox Code Playgroud)
它说:
AttributeError: 'amara.tree.entity' object has no attribute 'HOP'
Run Code Online (Sandbox Code Playgroud)
任何的想法?