国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

JDOM Programming Part 2

2019-11-17 06:18:09
字體:
供稿:網(wǎng)友

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:



發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 且末县| 曲靖市| 景洪市| 开封县| 广昌县| 房产| 汽车| 天气| 金塔县| 达拉特旗| 平乡县| 深泽县| 潜山县| 利津县| 启东市| 苏尼特右旗| 凉山| 迭部县| 香格里拉县| 潼关县| 瑞金市| 镇平县| 墨玉县| 轮台县| 昭苏县| 台南县| 太谷县| 连云港市| 蓝田县| 水城县| 渑池县| 抚宁县| 靖边县| 茶陵县| 桐城市| 德州市| 安陆市| 永州市| 吴桥县| 正宁县| 改则县|