哪种语言是最简单,最快速的处理XML内容的工作? [英] Which language is easiest and fastest to work with XML content?

查看:11754
本文介绍了哪种语言是最简单,最快速的处理XML内容的工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有开发者对这些语言知识 - 红宝石,Python和.NET或Java。我们正在开发一个应用程序,将主要处理XML文档。大部分的工作是predefined XML文件转换成数据库表中,通过提供数据库的XML文档之间的映射,从创建数据库等报告,其中语言将是最容易和最快的一起工作? (这是一个网络应用程序)

We have developers with knowledge of these languages - Ruby , Python, .Net or Java. We are developing an application which will mainly handle XML documents. Most of the work is to convert predefined XML files into database tables, providing mapping between XML documents through database, creating reports from database etc. Which language will be the easiest and fastest to work with? (It is a web-app)

推荐答案

有关这方面的一个动态语言规则。为什么?这些映射很容易code和变化。你不必重新编译和重建。

A dynamic language rules for this. Why? The mappings are easy to code and change. You don't have to recompile and rebuild.

事实上,一个小聪明,你可以有你的XML XPATH标签 - >数据库表字段映射为Python的code不相交块主应用程序导入

Indeed, with a little cleverness, you can have your "XML XPATH to a Tag -> DB table-field" mappings as disjoint blocks of Python code that your main application imports.

Python的code块的您的配置文件。这不是一个的.ini 文件或的.properties 文件,该文件描述的配置。它的配置。

The block of Python code is your configuration file. It's not an .ini file or a .properties file that describes a configuration. It is the configuration.

我们使用Python,xml.etree和SQLAlchem​​y的(分开SQL你的程序),这是因为我们并用很少的努力和很大的灵活性运行。

We use Python, xml.etree and the SQLAlchemy (to separate the SQL out of your programs) for this because we're up and running with very little effort and a great deal of flexibility.


source.py

"""A particular XML parser.  Formats change, so sometimes this changes, too."""

import xml.etree.ElementTree as xml

class SSXML_Source( object ):
    ns0= "urn:schemas-microsoft-com:office:spreadsheet"
    ns1= "urn:schemas-microsoft-com:office:excel"
    def __init__( self, aFileName, *sheets ):
        """Initialize a XML source.
        XXX - Create better sheet filtering here, in the constructor.
        @param aFileName: the file name.
        """
        super( SSXML_Source, self ).__init__( aFileName )
        self.log= logging.getLogger( "source.PCIX_XLS" )
        self.dom= etree.parse( aFileName ).getroot()
    def sheets( self ):
        for wb in self.dom.getiterator("{%s}Workbook" % ( self.ns0, ) ):
            for ws in wb.getiterator( "{%s}Worksheet" % ( self.ns0, ) ):
                yield ws
    def rows( self ):
        for s in self.sheets():
            print s.attrib["{%s}Name" % ( self.ns0, ) ]
            for t in s.getiterator( "{%s}Table" % ( self.ns0, ) ):
                for r in t.getiterator( "{%s}Row" % ( self.ns0, ) ):
                    # The XML may not be really useful.
                    # In some cases, you may have to convert to something useful
                    yield r

model.py

"""This is your target object.  
It's part of the problem domain; it rarely changes.
"""
class MyTargetObject( object ):
    def __init__( self ):
        self.someAttr= ""
        self.anotherAttr= ""
        self.this= 0
        self.that= 3.14159
    def aMethod( self ):
        """etc."""
        pass

builder_today.py 一个多映射配置

"""One of many builders.  This changes all the time to fit
specific needs and situations.  The goal is to keep this
short and to-the-point so that it has the mapping and nothing
but the mapping.
"""

import model

class MyTargetBuilder( object ):
    def makeFromXML( self, element ):
        result= model.MyTargetObject()
        result.someAttr= element.findtext( "Some" )
        result.anotherAttr= element.findtext( "Another" )
        result.this= int( element.findtext( "This" ) )
        result.that= float( element.findtext( "that" ) )
        return result

loader.py

"""An application that maps from XML to the domain object
using a configurable "builder".
"""
import model
import source
import builder_1
import builder_2
import builder_today

# Configure this:  pick a builder is appropriate for the data:
b= builder_today.MyTargetBuilder()

s= source.SSXML_Source( sys.argv[1] )
for r in s.rows():
    data= b.makeFromXML( r )
    # ... persist data with a DB save or file write



要进行更改,你可以纠正一个建设者或创建一个新的建设者。您调节装载机源以识别构建器将被使用。你可以,没有太多的麻烦,使制造商的选择一个命令行参数。在动态语言动态的进口似乎有点小题大做了我,但他们都得心应手。

To make changes, you can correct a builder or create a new builder. You adjust the loader source to identify which builder will be used. You can, without too much trouble, make the selection of builder a command-line parameter. Dynamic imports in dynamic languages seem like overkill to me, but they are handy.

这篇关于哪种语言是最简单,最快速的处理XML内容的工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆