本文整理匯總了Python中xml.sax.make_parser方法的典型用法代碼示例。如果您正苦於以下問題:Python sax.make_parser方法的具體用法?Python sax.make_parser怎麽用?Python sax.make_parser使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類xml.sax
的用法示例。
在下文中一共展示了sax.make_parser方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_make_parser2
# 需要導入模塊: from xml import sax [as 別名]
# 或者: from xml.sax import make_parser [as 別名]
def test_make_parser2(self):
# Creating parsers several times in a row should succeed.
# Testing this because there have been failures of this kind
# before.
from xml.sax import make_parser
p = make_parser()
from xml.sax import make_parser
p = make_parser()
from xml.sax import make_parser
p = make_parser()
from xml.sax import make_parser
p = make_parser()
from xml.sax import make_parser
p = make_parser()
from xml.sax import make_parser
p = make_parser()
# ===========================================================================
#
# saxutils tests
#
# ===========================================================================
示例2: test_5027_1
# 需要導入模塊: from xml import sax [as 別名]
# 或者: from xml.sax import make_parser [as 別名]
def test_5027_1(self):
# The xml prefix (as in xml:lang below) is reserved and bound by
# definition to http://www.w3.org/XML/1998/namespace. XMLGenerator had
# a bug whereby a KeyError is raised because this namespace is missing
# from a dictionary.
#
# This test demonstrates the bug by parsing a document.
test_xml = StringIO(
'<?xml version="1.0"?>'
'<a:g1 xmlns:a="http://example.com/ns">'
'<a:g2 xml:lang="en">Hello</a:g2>'
'</a:g1>')
parser = make_parser()
parser.setFeature(feature_namespaces, True)
result = self.ioclass()
gen = XMLGenerator(result)
parser.setContentHandler(gen)
parser.parse(test_xml)
self.assertEqual(result.getvalue(),
start + (
'<a:g1 xmlns:a="http://example.com/ns">'
'<a:g2 xml:lang="en">Hello</a:g2>'
'</a:g1>'))
示例3: parse_to_iterate_probabilitytable
# 需要導入模塊: from xml import sax [as 別名]
# 或者: from xml.sax import make_parser [as 別名]
def parse_to_iterate_probabilitytable(self):
handler = SAX_Handler("iter", self.em_io_handler)
parser = make_parser()
parser.setContentHandler(handler)
for count in range(self.NUM_TRAINING_ITERATION):
print "Starting iteration: "+str(count+1)+" ..."
print "Resetting all counts to ZERO ..."
self.em_io_handler.reset_count_table()
print "Start parsing "+self.training_xmlfile+" ..."
parser.parse(self.training_xmlfile)
print "Ending iteration: "+str(count+1)+" ..."
print "Updating probability table ..."
self.em_io_handler.update_probability_table()
開發者ID:shashiongithub,項目名稱:Sentence-Simplification-ACL14,代碼行數:19,代碼來源:saxparser_xml_stanfordtokenized_boxergraph_traininggraph.py
示例4: parse
# 需要導入模塊: from xml import sax [as 別名]
# 或者: from xml.sax import make_parser [as 別名]
def parse(self):
"""
Loads the StyleSheets from the associated file, if it exists.
"""
try:
if os.path.isfile(self.__file):
parser = make_parser()
parser.setContentHandler(SheetParser(self))
with open(self.__file) as the_file:
parser.parse(the_file)
except (IOError, OSError, SAXParseException):
pass
#------------------------------------------------------------------------
#
# StyleSheet
#
#------------------------------------------------------------------------
示例5: parse
# 需要導入模塊: from xml import sax [as 別名]
# 或者: from xml.sax import make_parser [as 別名]
def parse(self):
"""
Loads the BookList from the associated file, if it exists.
"""
try:
parser = make_parser()
parser.setContentHandler(BookParser(self, self.dbase))
with open(self.file) as the_file:
parser.parse(the_file)
except (IOError, OSError, ValueError, SAXParseException, KeyError,
AttributeError):
LOG.debug("Failed to parse book list", exc_info=True)
#-------------------------------------------------------------------------
#
# BookParser
#
#-------------------------------------------------------------------------
示例6: parse
# 需要導入模塊: from xml import sax [as 別名]
# 或者: from xml.sax import make_parser [as 別名]
def parse(self):
"""
Loads the :class:`OptionList` from the associated file, if it exists.
"""
try:
if os.path.isfile(self.filename):
parser = make_parser()
parser.setContentHandler(OptionParser(self))
with open(self.filename, encoding="utf-8") as the_file:
parser.parse(the_file)
except (IOError, OSError, SAXParseException):
pass
#-------------------------------------------------------------------------
#
# OptionParser
#
#-------------------------------------------------------------------------
示例7: parse
# 需要導入模塊: from xml import sax [as 別名]
# 或者: from xml.sax import make_parser [as 別名]
def parse(self):
"""
Loads the OptionList from the associated file, if it exists.
"""
try:
if os.path.isfile(self.filename):
parser = make_parser()
parser.setContentHandler(OptionParser(self))
parser.parse(self.filename)
except (IOError, OSError, SAXParseException):
pass
#-------------------------------------------------------------------------
#
# OptionParser
#
#-------------------------------------------------------------------------
示例8: _flatsaxParse
# 需要導入模塊: from xml import sax [as 別名]
# 或者: from xml.sax import make_parser [as 別名]
def _flatsaxParse(fl):
"""
Perform a SAX parse of an XML document with the _ToStan class.
@param fl: The XML document to be parsed.
@type fl: A file object or filename.
@return: a C{list} of Stan objects.
"""
parser = make_parser()
parser.setFeature(handler.feature_validation, 0)
parser.setFeature(handler.feature_namespaces, 1)
parser.setFeature(handler.feature_external_ges, 0)
parser.setFeature(handler.feature_external_pes, 0)
s = _ToStan(getattr(fl, "name", None))
parser.setContentHandler(s)
parser.setEntityResolver(s)
parser.setProperty(handler.property_lexical_handler, s)
parser.parse(fl)
return s.document
示例9: scan
# 需要導入模塊: from xml import sax [as 別名]
# 或者: from xml.sax import make_parser [as 別名]
def scan(self):
if not has_xml:
Logs.error('no xml support was found, the rcc dependencies will be incomplete!')
return([],[])
parser=make_parser()
curHandler=XMLHandler()
parser.setContentHandler(curHandler)
fi=open(self.inputs[0].abspath(),'r')
try:
parser.parse(fi)
finally:
fi.close()
nodes=[]
names=[]
root=self.inputs[0].parent
for x in curHandler.files:
nd=root.find_resource(x)
if nd:nodes.append(nd)
else:names.append(x)
return(nodes,names)
示例10: test_5027_1
# 需要導入模塊: from xml import sax [as 別名]
# 或者: from xml.sax import make_parser [as 別名]
def test_5027_1(self):
# The xml prefix (as in xml:lang below) is reserved and bound by
# definition to http://www.w3.org/XML/1998/namespace. XMLGenerator had
# a bug whereby a KeyError is raised because this namespace is missing
# from a dictionary.
#
# This test demonstrates the bug by parsing a document.
test_xml = StringIO(
'<?xml version="1.0"?>'
'<a:g1 xmlns:a="http://example.com/ns">'
'<a:g2 xml:lang="en">Hello</a:g2>'
'</a:g1>')
parser = make_parser()
parser.setFeature(feature_namespaces, True)
result = self.ioclass()
gen = XMLGenerator(result)
parser.setContentHandler(gen)
parser.parse(test_xml)
self.assertEqual(result.getvalue(),
self.xml(
'<a:g1 xmlns:a="http://example.com/ns">'
'<a:g2 xml:lang="en">Hello</a:g2>'
'</a:g1>'))
示例11: main
# 需要導入模塊: from xml import sax [as 別名]
# 或者: from xml.sax import make_parser [as 別名]
def main():
xmlString = "<note>\n<to>Tove</to>\n<from>Jani</from>\n<heading>Reminder</heading>\n<body>Don't forget me this weekend!</body>\n</note>"
# bad
xml.sax.parseString(xmlString, ExampleContentHandler())
xml.sax.parse('notaxmlfilethatexists.xml', ExampleContentHandler())
sax.parseString(xmlString, ExampleContentHandler())
sax.parse('notaxmlfilethatexists.xml', ExampleContentHandler)
# good
defusedxml.sax.parseString(xmlString, ExampleContentHandler())
# bad
xml.sax.make_parser()
sax.make_parser()
print('nothing')
# good
defusedxml.sax.make_parser()
示例12: load_data_and_labels_xml_string
# 需要導入模塊: from xml import sax [as 別名]
# 或者: from xml.sax import make_parser [as 別名]
def load_data_and_labels_xml_string(stringXml):
"""
Load data and label from a string
the format is as follow:
<p>
bla bla you are a <rs type="insult">CENSURED</rs>,
and I will <rs type="threat">find and kill</rs> you bla bla
</p>
only the insulting expression is labelled, and similarly only the threat
"action" is tagged
Returns:
tuple(numpy array, numpy array): data and labels
"""
# as we have XML mixed content, we need a real XML parser...
parser = make_parser()
handler = TEIContentHandler()
parser.setContentHandler(handler)
parser.parseString(stringXml)
tokens = handler.getSents()
labels = handler.getAllLabels()
return tokens, labels
示例13: load_data_and_labels_xml_file
# 需要導入模塊: from xml import sax [as 別名]
# 或者: from xml.sax import make_parser [as 別名]
def load_data_and_labels_xml_file(filepathXml):
"""
Load data and label from an XML file
the format is as follow:
<p>
bla bla you are a <rs type="insult">CENSURED</rs>,
and I will <rs type="threat">find and kill</rs> you bla bla
</p>
only the insulting expression is labelled, and similarly only the threat
"action" is tagged
Returns:
tuple(numpy array, numpy array): data and labels
"""
# as we have XML mixed content, we need a real XML parser...
parser = make_parser()
handler = TEIContentHandler()
parser.setContentHandler(handler)
parser.parse(filepathXml)
tokens = handler.getSents()
labels = handler.getAllLabels()
return tokens, labels
示例14: load_data_and_labels_lemonde
# 需要導入模塊: from xml import sax [as 別名]
# 或者: from xml.sax import make_parser [as 別名]
def load_data_and_labels_lemonde(filepathXml):
"""
Load data and label from Le Monde XML corpus file
the format is ENAMEX-style, as follow:
<sentence id="E14">Les ventes de micro-ordinateurs en <ENAMEX type="Location" sub_type="Country"
eid="2000000003017382" name="Republic of France">France</ENAMEX> se sont ralenties en 1991. </sentence>
Returns:
tuple(numpy array, numpy array): data and labels
"""
# as we have XML mixed content, we need a real XML parser...
parser = make_parser()
handler = ENAMEXContentHandler()
parser.setContentHandler(handler)
parser.parse(filepathXml)
tokens = handler.getSents()
labels = handler.getAllLabels()
return tokens, labels