网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网络编程 > Java
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,Apache,Tomcat,phpmyadmin,Gzip,触发器,socket
网络编程:ASP教程,ASP.NET教程,PHP教程,JSP教程,C#教程,数据库,XML教程,Ajax,Java,Perl,Shell,VB教程,Delphi,C/C++教程,软件工程,J2EE/J2ME,移动开发
本月文章推荐
.分享:让Java程序带着jre一起上路.
.Java反编译的研究.
.Java替代C语言的可能性.
.Java继承的一个实例.
.使用异步Servlet扩展AJAX应用程序.
.AtEndOfLine 属性.
.read-Atleap-5-主逻辑1-的发表新.
.J2EE项目登录方式的改进设计与实.
.JavaDoc,在 Java 的注释上做文章.
.JDBC基础教程之驱动设置.
.Hibernate技巧(1):利用配置文.
.GenAndRun 0.1, 又一个.
.Java与XML联合编程之DOM篇(2).
.JAVA对JPEG图片进行处理.
.为什么TEXT字段不能存取大于4K的.
.EJB最佳实践:如何做实体bean的保.
.J2EE1.4新特性之EJB2.1的新特性.
.关于Rose的对话.
.JDBMonitor基本原理探究.
.讲解J2EE中XML配置文件的读取处理.

JDOM Programming Part 2

发表日期:2008-1-5


JDOM and XML Parsing, Part 2

By Jason Hunter

JDOM makes XML manipulation in Java easier than ever.

In the first article of this series, I introdUCed JDOM, an open-source library for Java-optimized XML data manipulations. I eXPlained how this alternative document object model was not built on DOM or modeled after DOM but was created to be Java-specific and thereby take advantage of Java's features, including method overloading, collections, reflection, and familiar programming idioms. I covered the important classes and started examining how to use JDOM in your applications. In this article, I'll take a look at XML Namespaces, ResultSetBuilder, XSLT, and XPath.

Working with Namespaces

JDOM provides robust, native support for XML Namespaces. JDOM was created after the namespace recommendation was published, so unlike other APIs there's no pre-namespace and deprecated leftovers. (See the sidebar "XML Namespaces" for more on namespaces.) In JDOM, namespaces are represented by a Namespace class:

Namespace xHtml = Namespace.getNamespace(
  "xhtml", "http://www.w3.org/1999/xhtml");

During construction, an object is given a name and can optionally be given a namespace:

elt.addContent(new Element("table", xhtml));

If no namespace is given, the element is constructed in "no namespace." An element's namespace is an intrinsic part of its type, so JDOM ensures that its namespace doesn't change when it moves around the document. If an element has no namespace and moves under an element that has a namespace, it explicitly does not inherit the namespace. Sometimes that causes confusion until you learn to separate the textual representation from the semantic structure.

The XMLOutputter class sorts out the namespace issues and ensures placement of all the "xmlns" declarations into the appropriate locations, even after a document's elements have been heavily shuffled around. By default, the class places the declarations where they're first necessary. If you want them declared further up the tree (in other Words, all declarations at the root), you can use the element.addNamespaceDeclaration() method to provide that guidance.

All JDOM element or attribute Accessor methods support an optional namespace argument indicating the namespace in which to look. This example points to the xhtml namespace:


上一篇:对于颓废的程序员我要说:...... 人气:506
下一篇:变态级JAVA程序员面试32问(转) 人气:643
浏览全部Java的内容 Dreamweaver插件下载 网页广告代码 祝你圣诞节快乐 2009年新年快乐