以前做的Jdom的简单总结

本文介绍JDOM库的主要组件,包括SAXBuilder、DOMBuilder及XMLOutputter等,用于XML文件的读写操作。此外还详细展示了如何使用Element类构建XML元素,并设置属性和文本内容。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


版本几经不记得了, 去年的

+--org.jdom.input.SAXBuilder

Builds a JDOM document from files, streams, readers, URLs, or a SAX InputSource instance using a SAX parser. The builder uses a third-party SAX parser (chosen by JAXP by default, or you can choose manually) to handle the parsing duties and simply listens to the SAX events to construct a document.

 

+--org.jdom.input.DOMBuilder

Builds a JDOM org.jdom.Document from a pre-existing DOM org.w3c.dom.Document. Also handy for testing builds from files to sanity check SAXBuilder.

 

+--org.jdom.output.XMLOutputter

The outputter can manage many styles of document formatting, from untouched to pretty printed. The default is to output the document content exactly as created, but this can be changed by setting a new Format object.

 

void output(Document doc, java.io.OutputStream out)

   This will print the Document to the given output stream.

 

+--org.jdom.*

 

Structure

Document
DocType

  Comment

  Element

  Attribute

  ProcessingInstruction

 

  Data types
CDATA
Text

  Namespace

  EntityRef


Others
DefaultJDOMFactory

  Creates the standard top-level JDOM classes (Element, Document, Comment, etc). A subclass of this factory might construct custom classes.


UncheckedJDOMFactory

  Special factory for building documents without any content or structure checking.


Verifier

  A utility class to handle well-formedness checks on names, data, and other verification tasks for JDOM. The class is final and may not be subclassed.

 

Content
Superclass for JDOM objects which can be legal child content of Parent nodes. Such as Comment, DocType, Element, EntityRef, ProcessingInstruction, Text
<fibonacci index="6">8</fibonacci>

The first thing that occurs to me is this:

Element element = new Element("fibonacci");

element.setText("8");

element.setAttribute("index", "6");

<sequence>

  <number>3</number>

  <number>5</number>

</sequence>

 

First you need to create three Element objects, two for number elements and one for the sequence element. Then you need to add the number elements to the sequence element in the order you want them to appear. For example,

Element element = new Element("sequence");

Element firstNumber = new Element("number");

Element secondNumber = new Element("number");

firstNumber.setText("3");

secondNumber.setText("5");

element.addContent(firstNumber);

element.addContent(secondNumber);





 

 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值