ITPUB??ì3
ITPUB论坛 » WEB程序开发 » perl use XML::DOM; failuer???

新一届的微软MVP评选已经开始,欢迎各位推荐!

标题: perl use XML::DOM; failuer???
离线 liyihongcug
高级会员



精华贴数 1
个人空间 0
技术积分 9579 (124)
社区积分 1043 (930)
注册日期 2004-7-15
论坛徽章:8
会员2007贡献徽章铁扇公主授权会员2008年新春纪念徽章开发板块每日发贴之星数据库板块每日发贴之星
开发板块每日发贴之星ITPUB新首页上线纪念徽章    

发表于 2008-1-12 13:50 
perl use XML::DOM; failuer???

perl 理论 上是支持的 use XML:OM;  
但是在我的环境下Can't locate XML/DOM.pm in @INC (@INC contains: C:/Perl/site/lib C:/Perl/lib .
at C:\e.pl line 3.
BEGIN failed--compilation aborted at C:\e.pl line 3.


如何解决 ???/

附加:



Perl 为 XML 开发人员提供了一套非常丰富的模块和库,足以与其它语言相媲美。Perl 社区早期曾快速开发出 XML 工具。Perl/XML 社区现在仍保持着相当的活力,它不仅以惊人地速度支持新的协议和标准,还在 XML 的常规发展中起到了积极作用。Perl 的可扩展性使 C 和 C++ 模块能够简便地集成到 Perl 框架中,从而提供了一种速度和易用性的组合。

下列工具是我从开发 Perl/XML 工具和应用程序的经历中选出的比较中意的工具,也有从各种邮递列表、杂志和 Web 页面中收集的广受欢迎的工具。 这些工具将帮助您立即开发专业的基于 XML 的应用程序。

语法分析器和对象模型

从 XML 早期开始,XML 语法分析器就已经可用于 Perl。XML::Parser 模块是一个用于 James Clark 的出色的 expat 语法分析器的 Perl 接口,它是大多数其它分析和操纵模块的基础。XML::Simple 为简单的 XML 文件提供了一个直观的纯 Perl 语法分析器,而且大多数分析模块都支持 SAX API。

Perl 还对各种 XML 对象模型(包括 DOM、Grove 和 Twig)有很好的支持。各种各样的软件包提供了 DOM 或类似 DOM 的处理选项, 包括纯 Perl XML:OM 模型、XML::LibXML、XML::XPath、Orchard 和即将发行的 Sablotron:OM 软件包。 通过 Grove、Twig 和 PYX 模型,也可使用备用的处理模型。Twig 对大型文档尤其有用,它允许处理文档的各个段而无需对整个文档进行分析。

XML::Parser  用于 James Clark 的 XML 语法分析器 expat 的 Perl 接口
XML::Simple  用于读写 XML 的普通 API,最好与 XML 格式的配置文件一起使用
XML::XPath  XPath 规范的完整实现。
XML:OM  XML::Parser 的 Perl 扩展,构建面向对象的数据结构并具有遵从 DOM 级别 1 的接口。作为 libxml-enno 的一部分分发。
XML::LibXML  gnome libxml2 库的 Perl 接口,用于高性能的 DOM 处理。
XML::Grove  使用 Perl 散列树对已分析的 XML、HTML 或 SGML 实例组成的信息集进行简单访问
XML::Twig  XML 文档的树型接口,允许对超大型文档一段段地处理
libxml-perl  Perl 模块、脚本和文档的集合,用于在 Perl 中使用 XML。libxml-perl 软件与 XML::Parser、PerlSAX、XML:OM、XML::Grove 等一起工作。
XML::Schematron  基于 XSLT 的 XML 验证模块
Orchard  用于 XML 和 XML 表示的数据的事件流和树型视图的轻量级 API
Xerces Perl  “Apache XML 项目”中的 Xerces XML 语法分析器的 Perl 接口
REX  对有常规表达式的 XML 文档进行初步分析
PYX  至 PYX 生成器的 XML





回页首




XML 转换器、编写器和读取器

Perl 因其在与各种类型的旧有系统的连接中拥有丰富的选项而闻名。利用这些连接和将 Perl 数据结构转换成 XML 的设施,Perl 成为一个为现有系统创建 XML 接口的出色平台。 诸如 XML::Edifact、DBIx::XML_RDB、XML::CSV、XML::Generator、XML:umper 和 XML::Writer 等扩展都可以对 Perl 数据结构、XML 和其它格式之间的数据进行各个方面的序列化和非序列化处理。

XML::Generator  在 Perl 内生成 XML 的模块
XML:umper  将 Perl 数据序列化和非序列化为 XML 的模块
XML::Writer  编写 XML 文档的 Perl 程序的帮助器模块。该模块处理所有属性值和字符数据的转义,并构造各种标记。
XML::Edifact  将 UN/Edifact 文档转换成 XML 的模块





回页首




协议和库

通常,Perl 会迅速支持新的协议和标准。 对于 SOAP、WDDX、RSS、XML-RPC 和 Microsoft 的 BizTalk 都有扩展。

SOAP::Lite  SOAP 协议的卓越实现
SOAP/Perl  基于 XML 的协议,用于以与平台无关的方式访问服务、对象和服务器
WDDX.pm  在 Perl、Java 和 Cold Fusion 等各种语言之间交换数据的协议。该模块将 Perl 变量和 WDDX 信息包互相转换。
XML::RSS  创建和维护 Rich Site Summary (RSS) 文件的基本框架。RSS 主要用来分发新闻标题(通常称为通道)。





回页首




商业产品

大多数 Perl 扩展都在开发源码的模型下享有社区支持。Perl 的商业系统和软件包支持比 Java 等语言的系统和软件包要少得多。

VelociGen XML Server 是一种商业产品(出自我工作的公司),它使用 Perl 作为一种交换和处理 XML 文档并创建基于 Web 服务的应用程序的语言。 Open Source Axkit 也使用了商业支持,它使用 XML 提供 Web 发布和内容管理。

AxKit  开放源码的 XML Web 发布和内容管理
VelociGenX  Web 服务平台,具有数据库和旧系统连接性。使 Perl 接口用于分析、操纵和变换 XML 文档。





回页首




样式表和查询语言

XML 已有一套查询和变换数据的相关标准。其中两个最常用的是:“可扩展样式表语言变换 (XSLT)”和“XML 路径语言 (XPath)”。 XPath 提供了一种公共语法和功能来寻址和搜索 XML 文档各个部分。XSLT 使用 XPath 来实现 XML 文档到其它 XML 文档的变换。

XML::XSLT  XSL 模板处理的 Perl 实现。XML::XSLT 执行在 XSL 样式表中指定的到 XML 文件的变换。
XML::XPath  W3C 的 XPath 规范的实现
XML::QL  称为“XML-QL: XML 查询语言”的 W3C 注释的实现。使用户能够象数据库那样查询 XML 文档,并描述输出的构造。
XML::XQL  XQL 规范的 Perl 实现,允许对 XML 树型结构(如 XML:OM)进行 XQL 查询。作为 libxml-enno 的一部分分发。
XML::LibXSLT  gnome libxslt 库的 Perl 接口,用于高性能的 XSLT 处理。
XML::XSLT::Wrapper  各种 XSLT 模块的通用封装器
XML::Xalan  Apache Xalan XSLT 库的 Perl 接口





回页首




数据库接口

Perl 长期以来一直通过 DBD/DBI 模块享有卓越的数据库支持。DBIx::XML_RDB 使用这些模块构建所有流行数据库的 XML 封装器。XML::CSV 为以文本分隔的文件(如通用的以逗号分隔的值和以制表符定界的格式)提供了类似支持。

DBIx::XML_RDB  Perl 扩展,用于从诸如数据库的现有 DBI 数据源创建 XML
XML::CSV  将以逗号分隔的值转换为 XML



参考资料

您可以参阅本文在 developerWorks 全球站点上的 英文原文.


通过单击本文顶部或底部的 论坛,可以参加本文的 论坛。


CPAN 一直是 查找 Perl XML 模块的优秀资源


要了解有关用 Perl 和其它脚本语言操纵 XML 文档的详细信息,请参阅 developerWorks 上的 XML and scripting languages。


要想了解提供了创建高性能、由数据库驱动的动态网站的框架的联机系统,请参阅 Alex Shah 和 Parand T. Darugar 在 1998 Perl 会议发表的 High Performance Web Applications using Perl, Display Templates, XML, and Database Content 。


在 Perl XML FAQ处获取常见问题的解答。


通过将消息为 SUBSCRIBE Perl-XML 的电子邮件发送至 Lyris@ActiveState.com,订阅 perl-xml 邮递列表。


如果想知道 IBM 的 WebSphere Application Server (WAS) 是如何支持 XML 开发的, 请参阅 WAS 高级版 3.5 联机帮助中关于 XML 的技术背景信息。


只看该作者    顶部
离线 liyihongcug
高级会员



精华贴数 1
个人空间 0
技术积分 9579 (124)
社区积分 1043 (930)
注册日期 2004-7-15
论坛徽章:8
会员2007贡献徽章铁扇公主授权会员2008年新春纪念徽章开发板块每日发贴之星数据库板块每日发贴之星
开发板块每日发贴之星ITPUB新首页上线纪念徽章    

发表于 2008-1-12 13:51 
错误在  use XML:OM;
#!/usr/bin/perl

use XML:OM;
#use XML::Twig;

# 创建XML的最外层元素
my $xml = "<MyXML/>";

# 通过XML:OM::Parser解析外层元素,创建基础XML文档
# XML:OM::Parser:arse函数的返回值为 XML:OM:ocument 类
my $parser = new XML:OM::Parser;
my $dom = $parser->parse($xml);

# 生成Book节点
# createElement的返回值为 XML:OM::Element 类
# XML:OM::Element 的父类是 XML:OM::Node 类
my $book = $dom->createElement("Book";
# 设置节点属性
$book->setAttribute("title", "My First Book";
$book->setAttribute("author", "charlee";

# 生成Chapter节点
my $chapter = $dom->createElement("Chapter";
$chapter->setAttribute("id", "1";
# 生成一个文本节点
my $title = $dom->createTextNode("My First Chapter";
$chapter->appendChild($title);

# 添加Chapter到Book
$book->appendChild($chapter);

# 添加Book到XML文档
$dom->getDocumentElement->appendChild($book);

# 利用XML::Twig整理格式
my $twig = new XML::Twig;
$twig->set_indent(" "x4);
$twig->parse($dom->toString);
$twig->set_pretty_print("indented";

# 输出
print $twig->sprint;


只看该作者    顶部
离线 liyihongcug
高级会员



精华贴数 1
个人空间 0
技术积分 9579 (124)
社区积分 1043 (930)
注册日期 2004-7-15
论坛徽章:8
会员2007贡献徽章铁扇公主授权会员2008年新春纪念徽章开发板块每日发贴之星数据库板块每日发贴之星
开发板块每日发贴之星ITPUB新首页上线纪念徽章    

发表于 2008-1-12 14:49 
???
  use   XML:OM;   
  my   $parser   =   new   XML:OM::Parser;   
  my   $doc   =   $parser->parsefile   ("file.xml";   
    #   print   all   HREF   attributes   of   all   CODEBASE   elements   
  my   $nodes   =   $doc->getElementsByTagName   ("CODEBASE";   
  my   $n   =   $nodes->getLength;   
    for   (my   $i   =   0;   $i   <   $n;   $i++)   
    {   
            my   $node   =   $nodes->item   ($i);   
            my   $href   =   $node->getAttributeNode   ("HREF";   
            print   $href->getValue   .   "\n";   
    }   
    #   Print   doc   file   
    $doc->printToFile   ("out.xml";   
    #   Print   to   string   
    print   $doc->toString;   
   
  
Top

2 楼xyzxyz1111(程序员的自我修养)回复于 2006-03-09 16:19:41 得分 0 use   XML:OM;   
   
   
    my   $parser   =   new   XML:OM::Parser;   
    my   $doc   =   $parser->parsefile   ("file.xml";   
   
   
    #   print   all   HREF   attributes   of   all   CODEBASE   elements   
    my   $nodes   =   $doc->getElementsByTagName   ("CODEBASE";   
    my   $n   =   $nodes->getLength;   
   
   
    for   (my   $i   =   0;   $i   <   $n;   $i++)   
    {   
            my   $node   =   $nodes->item   ($i);   
            my   $href   =   $node->getAttributeNode   ("HREF";   
            print   $href->getValue   .   "\n";   
    }   
   
   
    #   Print   doc   file   
    $doc->printToFile   ("out.xml";   
   
    #   Print   to   string   
    print   $doc->toString;   
   
    #   Avoid   memory   leaks   -   cleanup   circular   references   for   garbage   collection   
    $doc->dispose;


只看该作者    顶部
离线 liyihongcug
高级会员



精华贴数 1
个人空间 0
技术积分 9579 (124)
社区积分 1043 (930)
注册日期 2004-7-15
论坛徽章:8
会员2007贡献徽章铁扇公主授权会员2008年新春纪念徽章开发板块每日发贴之星数据库板块每日发贴之星
开发板块每日发贴之星ITPUB新首页上线纪念徽章    

发表于 2008-1-12 14:54 
unshift (@INC,"/usr/local/share/perl/5.8.8/XML/Parser/");
use Expat;


只看该作者    顶部
离线 liyihongcug
高级会员



精华贴数 1
个人空间 0
技术积分 9579 (124)
社区积分 1043 (930)
注册日期 2004-7-15
论坛徽章:8
会员2007贡献徽章铁扇公主授权会员2008年新春纪念徽章开发板块每日发贴之星数据库板块每日发贴之星
开发板块每日发贴之星ITPUB新首页上线纪念徽章    

发表于 2008-1-12 15:03 
: How do I read xml file in perl?
--------------------------------------------------------------------------------

Dear Kevin,

Thanks for your reply.
I am using Unix machine.I am trying to install required modules by following command.

perl -MCPAN -e shell 'install XML:OM'

thenit is asking so many questions.How do i know hich one need to give.Is there any specific procedure need to follow.

It is giving the following when i run the command.

fmc /opt/fmc> perl -MCPAN -e shell 'install XML:OM'


/opt/fmc/.cpan/CPAN/MyConfig.pm initialized.


CPAN is the world-wide archive of perl resources. It consists of about
100 sites that all replicate the same contents all around the globe.
Many countries have at least one CPAN site already. The resources
found on CPAN are easily accessible with the CPAN.pm module. If you
want to use CPAN.pm, you have to configure it properly.

If you do not want to enter a dialog now, you can answer 'no' to this
question and I'll try to autoconfigure. (Note: you can revisit this
dialog anytime later by typing 'o conf init' at the cpan prompt.)

Are you ready for manual configuration? [yes] yes


The following questions are intended to help you with the
configuration. The CPAN module needs a directory of its own to cache
important index files and maybe keep a temporary mirror of CPAN files.
This may be a site-wide directory or a personal directory.



I see you already have a directory
/opt/fmc/.cpan
Shall we use it as the general CPAN build and cache directory?

CPAN build and cache directory? [/opt/fmc/.cpan] /opt/fmc/.cpan


If you want, I can keep the source files after a build in the cpan
home directory. If you choose so then future builds will take the
files from there. If you don't want to keep them, answer 0 to the
next question.



How big should the disk cache be for keeping the build directories
with all the intermediate files?

Cache size for build directory (in MB)? [10] 10


By default, each time the CPAN module is started, cache scanning
is performed to keep the cache size in sync. To prevent from this,
disable the cache scanning with 'never'.

Perform cache scanning (atstart or never)? [atstart] atstart


To considerably speed up the initial CPAN shell startup, it is
possible to use Storable to create a cache of metadata. If Storable
is not available, the normal index mechanism will be used.

Cache metadata (yes/no)? [yes] yes


The next option deals with the charset your terminal supports. In
general CPAN is English speaking territory, thus the charset does not
matter much, but some of the aliens out there who upload their
software to CPAN bear names that are outside the ASCII range. If your
terminal supports UTF-8, you say no to the next question, if it
supports ISO-8859-1 (also known as LATIN1) then you say yes, and if it
supports neither nor, your answer does not matter, you will not be
able to read the names of some authors anyway. If you answer no, names
will be output in UTF-8.

Your terminal expects ISO-8859-1 (yes/no)? [yes] yes


The CPAN module can detect when a module that which you are trying to
build depends on prerequisites. If this happens, it can build the
prerequisites for you automatically ('follow'), ask you for
confirmation ('ask'), or just ignore them ('ignore'). Please set your
policy to one of the three values.

Policy on building prerequisites (follow, ask or ignore)? [ask] ask


The CPAN module will need a few external programs to work properly.
Please correct me, if I guess the wrong path for a program. Don't
panic if you do not have some of them, just press ENTER for those. To
disable the use of a download program, you can type a space followed
by ENTER.

Where is your gzip program? [/usr/bin/gzip] /usr/bin/gzip
Where is your tar program? [/usr/bin/tar] /usr/bin/tar
Warning: unzip not found in PATH
Where is your unzip program? []
Where is your make program? [/usr/bin/make] /usr/bin/make
Warning: lynx not found in PATH
Where is your lynx program? []
Warning: wget not found in PATH
Where is your wget program? []
Warning: ncftpget not found in PATH
Where is your ncftpget program? []
Warning: ncftp not found in PATH
Where is your ncftp program? []
Where is your ftp program? [/usr/bin/ftp] /usr/bin/ftp
What is your favorite pager program? [/usr/bin/more] /usr/bin/more
What is your favorite shell? [/usr/bin/ksh]


Every Makefile.PL is run by perl in a separate process. Likewise we
run 'make' and 'make install' in processes. If you have any
parameters (e.g. PREFIX, LIB, UNINST or the like) you want to pass
to the calls, please specify them here.

If you don't understand this question, just press ENTER.

Parameters for the 'perl Makefile.PL' command?
Typical frequently used settings:

POLLUTE=1 increasing backwards compatibility
LIB=~/perl non-root users (please see manual for more hints)

Your choice: []
Parameters for the 'make' command?
Typical frequently used setting:

-j3 dual processor system

Your choice: []
Parameters for the 'make install' command?
Typical frequently used setting:

UNINST=1 to always uninstall potentially conflicting files

Your choice: []


Sometimes you may wish to leave the processes run by CPAN alone
without caring about them. As sometimes the Makefile.PL contains
question you're expected to answer, you can set a timer that will
kill a 'perl Makefile.PL' process after the specified time in seconds.

If you set this value to 0, these processes will wait forever. This is
the default and recommended setting.

Timeout for inactivity during Makefile.PL? [0]


If you're accessing the net via proxies, you can specify them in the
CPAN configuration or via environment variables. The variable in
the $CPAN::Config takes precedence.

Your ftp_proxy?
Your http_proxy?
Your no_proxy?
You have no /opt/fmc/.cpan/sources/MIRRORED.BY
I'm trying to fetch one
LWP not available

Please, install Net::FTP as soon as possible. CPAN.pm installs it for you
if you just type
install Bundle::libnet

Issuing "/usr/bin/ftp -n"

ftp: connect to address ::ffff:153.106.5.70: A remote host did not respond within the timeout period.
Trying ::ffff:199.239.233.95...
ftp: connect to address ::ffff:199.239.233.95: A remote host did not respond within the timeout period.
Trying ::ffff:153.106.5.70...
ftp: connect: A remote host did not respond within the timeout period.
Not connected.
Local directory now /opt/fmc/.cpan/sources
Not connected.
Not connected.
Not connected.
Not connected.
Not connected.
Bad luck... Still failed!
Can't access URL ftp://ftp.perl.org/pub/CPAN/MIRRORED.BY.

Please check, if the URLs I found in your configuration file () are valid.
The urllist can be edited. E.g. with 'o conf urllist push ftp://myurl/'

Could not fetch MIRRORED.BY
CPAN.pm needs at least one URL where it can fetch CPAN files from.

Please enter your CPAN site: [] CPAN.pm needs at least one URL where it can fetch CPAN files from.

Please enter your CPAN site: []

--------------------------------------------------------------------------------

Reply
  numberwhun
Moderator
1,297 Posts  August 28th, 2007
12:37 PM
#6  


Re: How do I read xml file in perl?
--------------------------------------------------------------------------------

This is your typical CPAN configuration. You only really need to go through this once, unless you decide to change something later. Here are my three suggestions.

1. For this line: "Policy on building prerequisites (follow, ask or ignore)? [ask] "

I always choose "follow". That way, CPAN automatically downloads, builds and installs any prerequisites to the module(s) that I am installing.

2. Make sure you install all of the programs it is looking for. In other words, take this list:

Where is your gzip program? [/usr/bin/gzip] /usr/bin/gzip
Where is your tar program? [/usr/bin/tar] /usr/bin/tar
Warning: unzip not found in PATH
Where is your unzip program? []
Where is your make program? [/usr/bin/make] /usr/bin/make
Warning: lynx not found in PATH
Where is your lynx program? []
Warning: wget not found in PATH
Where is your wget program? []
Warning: ncftpget not found in PATH
Where is your ncftpget program? []
Warning: ncftp not found in PATH
Where is your ncftp program? []
Where is your ftp program? [/usr/bin/ftp] /usr/bin/ftp
What is your favorite pager program? [/usr/bin/more] /usr/bin/more
What is your favorite shell? [/usr/bin/ksh]


and make sure that any program not listed is installed before re-running it.

3. After these questions, you will be prompted to select the sites you want to include in your search list (URL's). you would list them by using the number of the sites, separated by a space. I include 2 through 56 ( I think that's the highest one), only I do them in reverse order: ie: 56 55 54 53 52 51 50 ........
until they are all listed. Sure, this is overkill, but if I am looking for a module listed on cpan and its only on one of the mirrors (for example), then I will find it eventually. The reason I list them in reverse order is because the cpan urls are at the end (in the 50's) and seem to respond all the time.

I hope this helped!

Regards,

Jeff

--------------------------------------------------------------------------------

Reply


只看该作者    顶部
离线 liyihongcug
高级会员



精华贴数 1
个人空间 0
技术积分 9579 (124)
社区积分 1043 (930)
注册日期 2004-7-15
论坛徽章:8
会员2007贡献徽章铁扇公主授权会员2008年新春纪念徽章开发板块每日发贴之星数据库板块每日发贴之星
开发板块每日发贴之星ITPUB新首页上线纪念徽章    

发表于 2008-1-12 15:07 

只看该作者    顶部
离线 liyihongcug
高级会员



精华贴数 1
个人空间 0
技术积分 9579 (124)
社区积分 1043 (930)
注册日期 2004-7-15
论坛徽章:8
会员2007贡献徽章铁扇公主授权会员2008年新春纪念徽章开发板块每日发贴之星数据库板块每日发贴之星
开发板块每日发贴之星ITPUB新首页上线纪念徽章    

发表于 2008-1-12 15:22 
windows下需要下载1个模块  已经确定


只看该作者    顶部
 
    

相关内容


CopyRight 1999-2006 itpub.net All Right Reserved.
北京皓辰广域网络信息技术有限公司. 版权所有
E-mail:Webmaster@itpub.net
京ICP证:010037号 联系我们 法律顾问