XML认证知识点:DOM Parser
来源:才华咖 本文已影响2.26W人
来源:才华咖 本文已影响2.26W人
DOM Document 是以层次结构组织起来的节点,或信息片段的集合。这种层次结构允许开发者浏览树来查找特定信息。通常,分析结构需要在完成任何工作之前装入整个文档并且装入层次结构。
基本的应用程序
从创建基本的应用程序,名为 OrderProcessor 的类开始。
import mentBuilder;
import mentBuilderFactory;
import ;
import ment;
public class OrderProcessor {
public static void main (String args[]) {
File docFile = new File("");
Document doc = null;
try {
DocumentBuilderFactory dbf = nstance();
DocumentBuilder db = ocumentBuilder();
doc = e(docFile);
} catch (Exception e) {
t("Problem parsing the file.");
}
}
}
首先,Java 导入必要的类,然后创建 OrderProcessor 应用程序。在本教程中的这个示例将只处理一个文件,所以为简短起见,该应用程序包含对它的直接引用。
应用程序在 try-catch 块外部定义了 Document 对象,以便在后面使用该对象。try-catch 使您能执行可能会抛出异常的一些操作,这样不会危及整个应用程序。如果异常抛出,则应用程序简单地执行相应的. catch 代码。
在 try-catch 块内部,应用程序创建 DocumentBuilderFactory,然后使用它来创建 DocumentBuilder。最后,DocumentBuilder 解析该文件以创建 Document。
编辑文档
更改节点数据
odeValue(elemValue);
添加节点
String totalString = new Double(total)ring();
Node totalNode = teTextNode(totalString);
//Document 对象创建新的文本节点,该节点带有作为值的 totalString
Element totalElement = teElement("total");
//创建新元素 total
ndChild(totalNode);
// 将节点添加到新的 total 元素。
rtBefore(totalElement, irstChild());
//将新元素添加到 Document,指定新的 Node,然后指定新 Node 在 Node 之前
除去节点
Node deadNode = arentNode()veChild(thisOrderItem);
替换节点
Element backElement = teElement("backordered");
//创建新元素 backordered
Node deadNode = arentNode()aceChild(backElement,thisOrderItem);
创建和设置属性
Element backElement = teElement("backordered");
//创建新元素 backordered
ttributeNode(teAttribute("itemid"));
//创建新属性 itemid
String itemIdString = ttributeNode("itemid")odeValue();
//取得thisOrderItem的属性itemid的值
ttribute("itemid", itemIdString);
//设置backElement的属性item的值,可以省略createAttribute
Node deadNode = arentNode()aceChild(backElement,thisOrderItem);
除去属性
Element thisOrder = (Element)(orderNum);
Element customer = (Element)lementsByTagName("cusomertid")(0);
veAttribute("limit");
//去除属性limit
英语短文Do Old Folks Still Appreciate Humor?
Jolie drops battle over perfume named Shilohy英语作文
At Climate Summit, Hope for Emissions Deal美文欣赏
XML认证知识点:XML Schema
XML认证教程:SAX Parser
Diaspora Finance Powers Global Development美文欣赏
Adobe认证Macromedia Flash8考试大纲
Adobe认证Premiere Pro CS4考试大纲
Efforts Urged to Improve Womens Reproductive Health英语阅读
Adobe认证Premiere Pro CS6考试大纲
GMAT语法知识点:Modifiers和Pronouns的故事
初中英语作文To Bea Computer Expert Is My Ideal
Adobe认证Macromedia Dreamweaver8考试大纲
Should women work after marriage英语作文
FilmsandTVProgrammes教案设计
高中英语作文:Smart tech makes life simpler
How did I spend your summer vaca英语作文
优秀英语作文:Happy Summer Holidays
Modern Technology Makes Life More Conv英语六级作文
对知识的认识作文5篇
Choice of large enterprises or small英语四级作文
Oracle认证考试知识点:修改sid的步骤
英语美文:Remember,a name is for life.
雅思口语范文:My Experience as an English Learner
PHP如何使用DOM和simplexml读取xml文档
英语阅读:VIT declines to acquire Ang Mo Kio property
My Plan for Summer Vacation英语作文
英语作文:The Merits of Computer Games
用Dreamweaver MX 2004与SQL数据库相连
托福英语写作范文:Examinations exert a pernicious influence on educat
XML认证知识点:DOM Parser
我的暑假计划My summer holiday plan英语作文
Summer Holiday Plan英语作文
My Plan for the Summer Vacation英语作文
英语Lesson14家庭作业:Happymemories
一年级认识钟表知识点及教案
回报父母英语作文:When My Parents Are Old
教师资格证知识点
Plan summer holiday英语作文
英语材料阅读:with mental and physical disorders