本文整理汇总了Python中Ft.Xml.Domlette.NonvalidatingReader.parse方法的典型用法代码示例。如果您正苦于以下问题:Python NonvalidatingReader.parse方法的具体用法?Python NonvalidatingReader.parse怎么用?Python NonvalidatingReader.parse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Ft.Xml.Domlette.NonvalidatingReader
的用法示例。
在下文中一共展示了NonvalidatingReader.parse方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from Ft.Xml.Domlette import NonvalidatingReader [as 别名]
# 或者: from Ft.Xml.Domlette.NonvalidatingReader import parse [as 别名]
def __init__(self,iptFile,ctFile,truncTime):
# Read epidemic and truncate to truncTime
self.infectives = []
self.labels = []
epiFile = open(iptFile,'r')
for line in epiFile:
toks = line.split()
label = atoi(toks[0])
I = atof(toks[1])
N = atof(toks[2])
R = atof(toks[3])
if N <= truncTime: # Take individuals who have been notified by truncTime
if R > truncTime: # If R > truncTime, set R = truncTime
R = truncTime
self.infectives.append(Infective(label,I,N,R))
self.labels.append(label)
epiFile.close()
# Read in XML
conFile = Uri.OsPathToUri(ctFile)
xmlSrc = DefaultFactory.fromUri(conFile,stripElements=[(EMPTY_NAMESPACE,'*',1)])
self.doc = NonvalidatingReader.parse(xmlSrc)
# Remove from the contact DOM any contact info
# for individuals that are not present in labels
self.labels = set(self.labels)
for contact in self.doc.documentElement.xpath(u'tc:contact',explicitNss={u'tc':u'tracedcontacts'}):
contactLabel = atoi(contact.getAttributeNS(None,u'id'))
if contactLabel not in self.labels:
self.doc.documentElement.removeChild(contact)
示例2: Test
# 需要导入模块: from Ft.Xml.Domlette import NonvalidatingReader [as 别名]
# 或者: from Ft.Xml.Domlette.NonvalidatingReader import parse [as 别名]
def Test(tester):
tester.startGroup('Exercise namespace nodes')
isrc = InputSource.DefaultFactory.fromString(SRC_1, Uri.OsPathToUri(os.getcwd()))
doc = NonvalidatingReader.parse(isrc)
con = Context.Context(doc, 1, 1)
EXPR = '//namespace::node()'
expr = Compile(EXPR)
#expr is <AbbreviatedAbsoluteLocationPath: /descendant-or-self::node()/namespace::node()>
#expr._rel is <Step: namespace::node()>
#expr._step is <Step: descendant-or-self::node()>
tester.startTest(EXPR)
actual = expr.evaluate(con)
tester.compare(7, len(actual))
tester.testDone()
EXPR = '//node()/namespace::node()'
expr = Compile(EXPR)
tester.startTest(EXPR)
EXPECTED = []
actual = expr.evaluate(con)
tester.compare(7, len(actual))
tester.testDone()
EXPR = '//*/namespace::node()'
expr = Compile(EXPR)
tester.startTest(EXPR)
EXPECTED = []
actual = expr.evaluate(con)
tester.compare(7, len(actual))
tester.testDone()
EXPR = '/*/*/namespace::node()'
expr = Compile(EXPR)
tester.startTest(EXPR)
EXPECTED = []
actual = expr.evaluate(con)
tester.compare(6, len(actual))
tester.testDone()
EXPR = '/*/namespace::node()|/*/*/namespace::node()'
expr = Compile(EXPR)
tester.startTest(EXPR)
EXPECTED = []
actual = expr.evaluate(con)
tester.compare(7, len(actual))
tester.testDone()
EXPR = '//*'
expr = Compile(EXPR)
#expr is <AbbreviatedAbsoluteLocationPath: /descendant-or-self::node()/child::*>
tester.startTest(EXPR)
EXPECTED = []
actual = expr.evaluate(con)
tester.compare(4, len(actual))
tester.testDone()
return tester.groupDone()
示例3: run
# 需要导入模块: from Ft.Xml.Domlette import NonvalidatingReader [as 别名]
# 或者: from Ft.Xml.Domlette.NonvalidatingReader import parse [as 别名]
def run(self, iSrc):
"""
Given an InputSource, reads the document, processing XLinks therein.
Warning: The document will be modified in place.
"""
document = NonvalidatingReader.parse(iSrc)
xlinks = document.xpath("/descendant-or-self::*[@xlink:type]", explicitNss={"xlink": XLINK_NAMESPACE})
for link in xlinks:
xlink = XLinkElements.Create(link, iSrc)
xlink.process()
return document
示例4: Test
# 需要导入模块: from Ft.Xml.Domlette import NonvalidatingReader [as 别名]
# 或者: from Ft.Xml.Domlette.NonvalidatingReader import parse [as 别名]
def Test(tester):
tester.startGroup('CDATA sections in doc')
isrc = InputSource.DefaultFactory.fromString(SRC_1,
Uri.OsPathToUri(os.getcwd()))
doc = NonvalidatingReader.parse(isrc)
con = Context.Context(doc, 1, 1)
EXPR = '/doc/elem/text()'
expr = Compile(EXPR)
tester.startTest(EXPR)
actual = [ node.data for node in expr.evaluate(con) ]
tester.compare(actual, ["abc"]*3)
tester.testDone()
return tester.groupDone()
示例5: loadFromFile
# 需要导入模块: from Ft.Xml.Domlette import NonvalidatingReader [as 别名]
# 或者: from Ft.Xml.Domlette.NonvalidatingReader import parse [as 别名]
def loadFromFile(self, filename):
#rngParser = libxml2.relaxNGNewMemParserCtxt(VALIDATION_SCHEMA, len(VALIDATION_SCHEMA))
#rngContext = rngParser.relaxNGParse().relaxNGNewValidCtxt()
#file = fileRead(filename, 'r')
#doc = libxml2.parseDoc(file)
#if doc.relaxNGValidateDoc(rngContext) != 0:
# raise InvalidLibraryException(filename)
#for item in doc.xpathEval('/library/item'):
# self.addItem({'authors': map(lambda x: x.content, item.xpathEval('authors/author')),
# 'title': item.xpathEval('title')[0].content,
# 'type': item.xpathEval('type')[0].content,
# 'date': item.xpathEval('date')[0].content,
# 'language': item.xpathEval('language')[0].content})
factory = InputSource.DefaultFactory
schema = factory.fromString(VALIDATION_SCHEMA)
validator = RelaxNgValidator(schema)
file = Uri.OsPathToUri(filename, attemptAbsolute=1)
# validate file
if not(validator.isValid(factory.fromUri(file))):
raise InvalidLibraryException(filename)
doc = NonvalidatingReader.parse(factory.fromUri(file))
# read items from document
for item in doc.xpath('/library/item'):
self.addItem({'authors': map(lambda x: x.childNodes[0].nodeValue.strip(), item.xpath('authors/author')),
'title': item.xpath('title')[0].childNodes[0].nodeValue.strip(),
'type': item.xpath('type')[0].childNodes[0].nodeValue.strip(),
'date': item.xpath('date')[0].childNodes[0].nodeValue.strip(),
'language': item.xpath('language')[0].childNodes[0].nodeValue.strip()})