Node. For example, if you want to get an object named ID attribute, you can call GetAttribute ("id").
Our first DOM app!
Introduced a lot of concepts, let's go on. Our first application simply reads an XML document and outputs its content to standard output.
In a command line window, run the following command:
Java Domone sonnet.xml
This command will be loaded into our application and then let it
JTree superclass and Dom parsing objects, the constructor generates a TreeModel object to create an actual visual tree. By passing the DOM object to the Createtreenode () method to create a root node, the Createtreenode () method returns an object of the Defaultmutabletreenode type. This object is then used to create the treemodel of the tree.MethodPrivate Defaultmutabletreenode Createtreenode (Node root)This method takes a DOM node and then recursively in the child nodes until all the contacts
:
For example, you can configure the database connection pool here.
How to use java in a webxml File
If you want to retrieve all the values, we recommend that you parse WEB. XML and then set the values. If you want to retrieve a specific value, you can use the following:Two parameters can be defined in web. xml
requirements.Application examplesAn XML fragment for parsing is given below:Listing 1. XML FragmentDOM parsing XMLIntroduction to the DOM interface in Java: The DOM API in the JDK follows the Org.w3c.dom DOM specification, where the package provides interfaces such as Document, DocumentType, Node, NodeList, Element, which are Required to access the DOM document.
that for a well-structured XML, its nested structure is complete, and each start tag will always correspond to an end tag, and there will be no dislocation between tag nesting. Therefore, every call to the startelement () method is bound to correspond to a call to the endelement () method. In this way, push and pop appear in pairs. We only need to analyze the stack structure, you can easily know where the current tag is in the document structure.
, there are 3 JSON objects in the array, and each JSON object is separated by commas.
Using Java to read JSON data
In the JSON website we can see the various syntax to the JSON support, for Java is more mature is google-gson.
Its maven dependencies are as follows:
Now write the program to parse the following test.json:
{
"cat": "It",
Using DOM4J to parse the downloaded XML file, the Java program is as follows: Packagegao.map.preprocess;ImportJava.io.BufferedWriter;ImportJava.io.File;ImportJava.io.FileOutputStream;Importjava.io.IOException;ImportJava.io.OutputStreamWriter;Importjava.util.ArrayList;ImportJava.util.Iterator;Importjava.util.List;ImportOrg.dom4j.Attribute;Importorg.dom4j.Document;
used together with a variety of XML parser. The XML Parser we selected this time is Apache Crimson. XmlDocument (org. apache. crimson. tree. xmlDocument) is a class of Apache Crimson and is not included in the standard JAXP. No wonder the XmlDocument class cannot be found in the JAXP document. Now the problem arises. How can I use the XmlDocument class to update XML
can be used together with a variety of XML parser. The XML Parser we selected this time is Apache Crimson. XmlDocument (org. apache. crimson. tree. xmlDocument) is a class of Apache Crimson and is not included in the standard JAXP. No wonder the XmlDocument class cannot be found in the JAXP document. Now the problem arises. How can I use the XmlDocument class to update
When you want to transmit multiple data in the background on a webpage, sometimes the data is still multiple dynamic lists. when the data is complex, JavaScript programmers like to process them as JSON strings, the backend needs to parse the JSON string after receiving it. Fortunately, there is JSON-Lib. This Java class package is used to convert bean, MAP and
documents.The Doumentbuilder and documentbuilderfactory in the Javax.xml.parsers package are used to parse the XML document to generate the corresponding DOM document object.The Domsource class and Streamsource class in the Javax.xml.transform.dom and Javax.xml.transform.stream packages are used to write the updated DOM document to an XML file.Here is an example
expressions and java to parse csv files.
First, we provide a regular expression that matches the smallest unit of data in a csv file (for example, 1, 2, 3 is a row of data in the csv file, then 1 is a smallest unit of data in the csv file ):
"([^", \ N] * [, \ n]) * ([^ ", \ n] *" {2}) * [^ ", \ n] * "[] *, [] * | [^", \ n] * [] *, [] * | "([^ ", \ n] * [, \ n]) * ([^ ", \ n] *" {2}) * [^ ", \ n] * "[] * |
The struts configuration is as follows:
Models is a list set of queries. Data has been received in the flex foreground,
Turn left | turn right
Other data can be displayed normally, but only the date type does not know how to display it.
Turn left | turn right
The date in the database is:
Turn left | turn right
Turn left | turn right
The field indicates:
Year: year (when converting to XML format, it is to subtract the cur
document is transformed (translation. With this new function, we can easily write the newly generated or modified DOM tree back to the XML file. Let's take a look at the implementation of the Code, the main function of this Code is to links. add a new link node to the XML file:
Import javax. xml. parsers .*;Import javax.
Recently been busy with the Mentor project, a few days did not update, yesterday and today to study the next WWJ analysis shp file source code, now record, hope can help more people!Previous blog: World Wind Java Development Five-read local shp file only how to load shp files, not related to the analysis of SHP files, our blog immediately after the previous blog, using WWJ to parse shp files. First look at
In the JDK, a set of related compilation APIs can be initiated in Java to initiate the compilation process, parse the Java source file, and then obtain its syntax tree, which can be/library/java/javavirtualmachines/in the JDK's Tools.jar (OS X) Found in Jdk_version/contents/home/lib), but this is not a public API in Or
before you can start to work.
Dom_demo.xml File
DOMDemo. java parsing File
Package com. xml. dom parsing; import java. io. *; import org. w3c. dom. *; import javax. xml. parsers. *; public class DOMDemo {public static void main (String args []) throws Exception {// get the
Java Xml tutorial (9) Verify XML legitimacy through XSD in Java
The Java XML validation API can use XSD (XML Schema Definition) to verify the validity of the
opportunity to maintain a constant pool for each loaded class is "different from the string constant pool, which is just an ordered collection of literal values (such as class names, method names) and symbol references for that class. The string constant pool, which is shared by the entire JVM, is a symbol reference, such as int a = 5, and the parsing process converts it to the relative address of the obje
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.