以前做的Jdom的簡單總結


版本幾經不記得了, 去年的

+--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);





 

 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章