当前位置: 首页>>代码示例>>Python>>正文


Python libxml2.parseFile方法代码示例

本文整理汇总了Python中libxml2.parseFile方法的典型用法代码示例。如果您正苦于以下问题:Python libxml2.parseFile方法的具体用法?Python libxml2.parseFile怎么用?Python libxml2.parseFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在libxml2的用法示例。


在下文中一共展示了libxml2.parseFile方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __build_libxml2

# 需要导入模块: import libxml2 [as 别名]
# 或者: from libxml2 import parseFile [as 别名]
def __build_libxml2(target, source, env):
    """
    General XSLT builder (HTML/FO), using the libxml2 module.
    """
    xsl_style = env.subst('$DOCBOOK_XSL')
    styledoc = libxml2.parseFile(xsl_style)
    style = libxslt.parseStylesheetDoc(styledoc)
    doc = libxml2.readFile(str(source[0]),None,libxml2.XML_PARSE_NOENT)
    # Support for additional parameters
    parampass = {}
    if parampass:
        result = style.applyStylesheet(doc, parampass)
    else:
        result = style.applyStylesheet(doc, None)
    style.saveResultToFilename(str(target[0]), result, 0)
    style.freeStylesheet()
    doc.freeDoc()
    result.freeDoc()

    return None 
开发者ID:StatisKit,项目名称:StatisKit,代码行数:22,代码来源:__init__.py

示例2: resolver

# 需要导入模块: import libxml2 [as 别名]
# 或者: from libxml2 import parseFile [as 别名]
def resolver(URL, ID, ctxt):
    global resources

    if string.find(URL, '#') != -1:
        URL = URL[0:string.find(URL, '#')]
    if resources.has_key(URL):
        return(StringIO.StringIO(resources[URL]))
    log.write("Resolver failure: asked %s\n" % (URL))
    log.write("resources: %s\n" % (resources))
    return None

#
# Load the previous results
#
#results = {}
#previous = {}
#
#try:
#    res = libxml2.parseFile(RES)
#except:
#    log.write("Could not parse %s" % (RES))
    
#
# handle a valid instance
# 
开发者ID:flutter,项目名称:buildroot,代码行数:27,代码来源:check-relaxng-test-suite.py

示例3: resolver

# 需要导入模块: import libxml2 [as 别名]
# 或者: from libxml2 import parseFile [as 别名]
def resolver(URL, ID, ctxt):
    global resources

    if resources.has_key(URL):
        return(StringIO.StringIO(resources[URL]))
    log.write("Resolver failure: asked %s\n" % (URL))
    log.write("resources: %s\n" % (resources))
    return None

#
# Load the previous results
#
#results = {}
#previous = {}
#
#try:
#    res = libxml2.parseFile(RES)
#except:
#    log.write("Could not parse %s" % (RES))
    
#
# handle a valid instance
# 
开发者ID:flutter,项目名称:buildroot,代码行数:25,代码来源:check-relaxng-test-suite2.py

示例4: __transform_xmllint

# 需要导入模块: import libxml2 [as 别名]
# 或者: from libxml2 import parseFile [as 别名]
def __transform_xmllint(self, file, xsl_file, output, params = {}):
        import libxml2
        import libxslt

        new_params = {}
        keys = params.keys()
        for key in keys:
            new_params[key] = '"%s"' % params[key]
        params = new_params
            


        try:
            xml_doc = file
            # parse stylesheet
            styledoc = libxml2.parseFile(xsl_file)
            style = libxslt.parseStylesheetDoc(styledoc)
            # parse doc
            doc = libxml2.parseFile(xml_doc)
            result = style.applyStylesheet(doc, params)
            style.saveResultToFilename(output, result, 0)
            style.freeStylesheet()
            doc.freeDoc()
            result.freeDoc()
        except libxml2.parserError:
            return 1, ''
        return 0, '' 
开发者ID:paulhtremblay,项目名称:rtf2xml,代码行数:29,代码来源:xsl_convert.py

示例5: __init__

# 需要导入模块: import libxml2 [as 别名]
# 或者: from libxml2 import parseFile [as 别名]
def __init__(self, pipe):
        chirp_common.FileBackedRadio.__init__(self, None)
        self._filename = pipe
        if self._filename and os.path.exists(self._filename):
            self.doc = libxml2.parseFile(self._filename)
            validate_doc(self.doc)
        else:
            self.doc = libxml2.newDoc("1.0")
            radio = self.doc.newChild(None, "radio", None)
            radio.newChild(None, "memories", None)
            radio.newChild(None, "banks", None)
            radio.newProp("version", "0.1.1") 
开发者ID:mach327,项目名称:chirp_fork,代码行数:14,代码来源:generic_xml.py

示例6: load

# 需要导入模块: import libxml2 [as 别名]
# 或者: from libxml2 import parseFile [as 别名]
def load(self, filename=None):
        if not self._filename and not filename:
            raise errors.RadioError("Need a location to load from")

        if filename:
            self._filename = filename

        self.doc = libxml2.parseFile(self._filename)
        validate_doc(self.doc) 
开发者ID:mach327,项目名称:chirp_fork,代码行数:11,代码来源:generic_xml.py

示例7: __xml_scan

# 需要导入模块: import libxml2 [as 别名]
# 或者: from libxml2 import parseFile [as 别名]
def __xml_scan(node, env, path, arg):
    """ Simple XML file scanner, detecting local images and XIncludes as implicit dependencies. """
    # Does the node exist yet?
    if not os.path.isfile(str(node)):
        return []
    
    if env.get('DOCBOOK_SCANENT',''):
        # Use simple pattern matching for system entities..., no support 
        # for recursion yet.
        contents = node.get_text_contents()
        return sentity_re.findall(contents)

    xsl_file = os.path.join(scriptpath,'utils','xmldepend.xsl')
    if not has_libxml2 or prefer_xsltproc:
        if has_lxml and not prefer_xsltproc:
            
            from lxml import etree
            
            xsl_tree = etree.parse(xsl_file)
            doc = etree.parse(str(node))
            result = doc.xslt(xsl_tree)

            depfiles = [x.strip() for x in str(result).splitlines() if x.strip() != "" and not x.startswith("<?xml ")]
            return depfiles
        else:
            # Try to call xsltproc
            xsltproc = env.subst("$DOCBOOK_XSLTPROC")
            if xsltproc and xsltproc.endswith('xsltproc'):
                result = env.backtick(' '.join([xsltproc, xsl_file, str(node)]))
                depfiles = [x.strip() for x in str(result).splitlines() if x.strip() != "" and not x.startswith("<?xml ")]
                return depfiles
            else:
                # Use simple pattern matching, there is currently no support
                # for xi:includes...
                contents = node.get_text_contents()
                return include_re.findall(contents)

    styledoc = libxml2.parseFile(xsl_file)
    style = libxslt.parseStylesheetDoc(styledoc)
    doc = libxml2.readFile(str(node), None, libxml2.XML_PARSE_NOENT)
    result = style.applyStylesheet(doc, None)

    depfiles = []
    for x in str(result).splitlines():
        if x.strip() != "" and not x.startswith("<?xml "):
            depfiles.extend(x.strip().split())
    
    style.freeStylesheet()
    doc.freeDoc()
    result.freeDoc()

    return depfiles

# Creating the instance of our XML dependency scanner 
开发者ID:StatisKit,项目名称:StatisKit,代码行数:56,代码来源:__init__.py


注:本文中的libxml2.parseFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。