Document document = builder. parse (new File ("src/myClass. xml "); read (document );
The read method is written as follows:
/*** Display all information of all students * @ param document */public static void read (Document document) {// Obtain NodeList = document by using the student's label name. getElementsByTagName ("student"); for (int I = 0; I
The final running result is as follows:
Use the javax. xml. transform. stream. StreamResult object to represent the data destination.
some old programs used com. sun. xml packages. If you re-compile them now, it may fail. It must be for this reason. Later, JAXP and Apache Crimson were bundled together, such as JAXP 1.1. If you use JAXP 1.1, you do not need to download Apache Crimson and compile and run the above example (AddRecord. java ). The latest JAXP 1.2 EA (Early Access) is changed to a new one. Apache Xalan and Apache Xerces, which have better performance, are used as the XSLT processor and XML parser respectively, and
, so some old programs used com. sun. xml packages. If you re-compile them now, it may fail. It must be for this reason. Later, JAXP and Apache Crimson were bundled together, such as JAXP 1.1. If you use JAXP 1.1, you do not need to download Apache Crimson and compile and run the above example (AddRecord. java ). The latest JAXP 1.2 EA (Early Access) is changed to a new one. Apache Xalan and Apache Xerces, which have better performance, are used as the XSLT processor and XML parser respectively,
http://blog.csdn.net/u012325167/article/details/50943202There are several steps to generating an XML file using the DOM method:The first is to create the DOM tree (that is, to specify the content in the XML file):
Create a Documentbuilderfactory object
Creating Documentbuilder objects from Documentbuilderfactory objects
Creates a document object from the NewDocument () method of the Documentbuilder object that represents an XML file
Creating a root node through the createele
directly (Addrecord.java), you need to download and install Apache Crimson Extra.
Method Three: Using Transformerfactory and Transformer classes
The standard way to update the original XML document in JAXP is to invoke the XSLT engine, that is, to use the Transformerfactory and transformer classes. Take a look at the following Java code snippet:
First, you create a Domsource object that can be a
.
Method Three: Using Transformerfactory and Transformer classes
The standard way to update the original XML document in JAXP is to invoke the XSLT engine, that is, to use the Transformerfactory and transformer classes. Take a look at the following Java code snippet:
First, you create a Domsource object that can be an argument to a Document object
Doc represents the changed DOM tree.
Domsource doms = ne
first, JAXP, Dom introduction
Jaxp:java API for XML programing
Dom:document Object method
DOM Features:
(1) All the XML documents are put into memory for parsing, so memory consumption is consumed;
(2) to be able to the XML to be added to the search;
To become a DOM tree:
Second, DOM API
Dom's commonly used classes are: Documentbuilderfactory, Documentbuilder, Document, Node, NodeList, Element, Attribute, Transformerfactory, Transformer, Dom
Crimson Extra.
Method Three: Using Transformerfactory and Transformer classesThe standard way to update the original XML document in JAXP is to invoke the XSLT engine, that is, to use the Transformerfactory and transformer classes. Take a look at the following Java code snippet:
First, you create a Domsource object that can be an argument to a Document objectDoc represents the changed DOM tree.
first, JAXP, Dom introduction
Jaxp:java API for XML programing
Dom:document Object Method
DOM Features:
(1) The XML documents are all put into memory for parsing, thus consuming memory;
(2) to be able to increase the deletion of XML search;
Into the DOM tree:
Second, DOM API
Common DOM classes are: Documentbuilderfactory, Documentbuilder, Document, Node, NodeList, Element, Attribute, Transformerfactory, Transformer, Domsource, Streamresult a
file, follow these steps.Use the transformerfactory class in the javax. xml. Transform package to create an object:Transformerfactory transfactory = transformerfactory. newinstance ()The transfactory object obtained in the step calls the newtransformer () method to obtain a transformer object:Transformer transformer = transfactory. newtransformer ();The transformer class is in the javax. xml. Transform pac
1. Current mainstream Transformer implementationJava sdk requires that the XSLT transformer implement the abstract methods in the javax. xml. transform. TransformerFactory abstract class. This factory class becomes the entry for creating a specific Transformer instance. Currently, the mainstream implementations are:Saxon 6.x: com. icl. saxon. TransformerFactoryImplSaxon 7.x: net. sf. saxon. TransformerFactoryImplXalan: org. apache. xalan. processor. T
XML parser respectively, and cannot directly support Apache Crimson, therefore, if your development environment uses JAXP 1.2 EA or Java XML Pack (containing JAXP 1.2 EA), you cannot directly compile and run the above example (AddRecord. java), you need to download and install Apache Crimson.
Method 3: Use the TransformerFactory and Transformer classes
The standard method provided in JAXP to update the original XML document is to call the XSLT engin
The following is an example of a Java transit scheme:
Books. xml
View plaincopy to clipboardprint?
Books. XSL
View plaincopy to clipboardprint?
Convert java files:
View plaincopy to clipboardprint?Package com. LWF. test;Import javax. xml. Transform. result;Import javax. xml. Transform. transformer;Import javax. xml. Transform. transformerconfigurationexception;Import javax. xml. Transform. transformerexception;Import javax. xml. Transform. transformerfactory
. JAX-RPCA JAX-RPC is a Java API called remotely through xml. It is based on the SOAP technology and uses SOAP as the underlying protocol. In this way, developers only have methods, parameters, and return values visible, and the underlying soap communication is hidden, so developers do not need to deal with it directly.JAXM and JAX-RPC play an important role in Web Services.Supplement: Steps for finding the specific implementation of the JAXP frameworkJDK1.4 comes with the reference implementati
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.