JDOM Programming Part 2

2016-02-19 14:15 2 1 收藏

岁数大了,QQ也不闪了,微信也不响了,电话也不来了,但是图老师依旧坚持为大家推荐最精彩的内容,下面为大家精心准备的JDOM Programming Part 2,希望大家看完后能赶快学习起来。

【 tulaoshi.com - 编程语言 】

JDOM and XML Parsing, Part 2

By Jason Hunter

  JDOM makes XML manipulation in Java easier than ever.

(本文来源于图老师网站,更多请访问https://www.tulaoshi.com/bianchengyuyan/)

  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.

(本文来源于图老师网站,更多请访问https://www.tulaoshi.com/bianchengyuyan/)

  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:

  

来源:https://www.tulaoshi.com/n/20160219/1606566.html

延伸阅读
概述: Jdom是用Java语言读、写、操作XML的新API函数。Jason Hunter 和 Brett McLaughlin公开发布了它的测试版本。在直觉、简单和高效的前提下,这些API函数被最大限度的优化。 !-- frame contents -- !-- /frame contents -- 在接下来的篇幅里,Hunter 和 McLaughlin介绍怎么用Jdom去读写一个已经存在的XML文档。 ...
《无双大蛇z》激难赤壁凌统华彩part2 无双大蛇Z生存模式用什么人物好? 吕布、小乔、加拉夏 上来就使用无双乱舞或无双奥义的高机率人物——刘备 魏延 星彩 典韦 徐晃 曹仁 司马懿 孙坚 甘宁 大乔 左慈 妲己 太公望 源义经 百百目鬼 织田信长 武田信玄 腹部半藏 稻姬 石田三成 宁宁 风魔小太郎 卑弥呼 宫本武藏 加拉夏 上来就使用R1...
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; Memo1: TMemo; Button2: TButton; Button3: TButton; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Button3Click...
标签: Web开发
这篇文章讲的不错~把JDOM的基本操作实例化了,不过由于当时的作者用的JDOM版本还比较陈旧,所以部分代码会编译出错!支持中文也不好!所以,法老在
《质量效应2》全视频攻略part 7 (omega - archangel_s hideout) 《质量效应2》全视频攻略Part 7 (Omega - Archangel_s Hideout) 你能Hold住吗?质量效应2兰姐真人原型性感写真 澳大利亚演员伊冯娜·斯特拉霍夫斯基在签订为米兰达配音时,开发团队就决定以这位演员为模型打造这名游戏角色。 游戏造型 所以那些玩过《质量效应2》的玩家...

经验教程

22

收藏

84
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部