Javase Learning Notes XPath introduction with Web server (8)

Source: Internet
Author: User
Tags xpath

XPath is a separate path language, and the main purpose is to find the elements in the path. Then dom4j supports path lookups for XPath by default. There are two common methods: selectnodes ("XPath")        ? Queries all elements of the specified path selectSingleNode ("XPath")    ? Query the first element of a specified path?    Commonly used XPath path notation /AAA          Specifies the path to be written from the root of the XML document //BBB        Specifies that the search satisfies the element name from the entire XML /AAA/CCC/DDD /* specify all the elements under the path//*            specify to get all the elements/aaa/bbb[1] the  first element under the specified path, which must be the last element at the beginning of the path specified by the 1/aaa/bbb[last ()] [/  /@id          Specifies the property element to get//bbb[@id]        Specifies the element with attributes//bbb[@id = ' B1 ')    specifies the element of the property value//bbb[position () = Floor (last () Div 2 + 0.5) or Position () = Ceiling (last () Div 2 + 0.5)]
Case two: Using Dom4j+xpath to realize user login and registration

Code implementation:

1 . Write an information file for user login Users_login.xml<?xml version="1.0" encoding=" UTF-8 "?><users>  <user name="Jack" password="  Root"/></users>
2. Landing business Methods//provide a way to log in     Public StaticUser Login (string name, string password, file file) throws Exception {Document doc=getdoc (file); Node Node= Doc.selectsinglenode ("/users/user[@name = '"+name+"' and @password = '"+ Password +"']"); User User=NULL; if(Node! =NULL) {String Name_value= Node.valueof ("@name"); String Password_value= Node.valueof ("@password"); User=NewUser (Name_value, Password_value); }        returnuser; }
3. Registered Business logic Methods//provides a business logic to store a user     Public Static voidRegistuser (User user,file File) throws exception{Document Doc=getdoc (file); Element Root=doc.getrootelement (); Element New_user= Documenthelper.createelement ("User"). AddAttribute ("name", User.getname ()). AddAttribute ("Password", User.getpassword ());        Root.add (New_user); //persisting a Document object to a fileXMLWriter writer =NewXMLWriter (NewOutputStreamWriter (NewFileOutputStream (file),"UTF-8"));        Writer.write (DOC);    Writer.close (); }

Comparison: DOM vs SAX vs Dom4j+xpath

The DOM loads the XML file into memory as a DOM tree for parsing. Node, Element, Document, Text, attr, and so on.

Cons: XML files that cannot parse big data.

Precedence: You can do anything with XML.

Sax divides the parsing of XML into different time periods, so it is necessary to create a developer's own event handler class.

Startdocument ()/enddocument startelement ()/endelement () Characater ()

Disadvantage: You can only get elements.

Priority: Use the event mechanism fast.

Dom4j+xpath

Dom4j+xpath combines the advantages of DOM and sax and rejects the drawbacks of both.

Summarize the main article: priority to use Dom4j+xpath

Questions: 1 . Use the DOM to store a node, but the same root element disappears in the XML file.   is that the DOM tree is not written back to the XML file.  New  Domsource (DOM)2. Inserts an element before the specified position. The   method of the immediate parent class should be called when the InsertBefore () method is called. 
summarize the principles and ideas of parsing XML. Documentbuilderfactory/documentbuilder    ttransformerfactory/ ttransformersaxpaserfactory/ Saxparsersaxreader/xmlwriter/docuementhelper/docuement
Introduction to Web Servers

A Web server is a computer that has Web server software installed. Web server Software is a software that provides external access to the resources of the folder you manage.

The main task of the Web server software is to obtain the user's request resource, locate the resource in the Web site you manage according to the name of the resource, and use the input stream to read the resource data and send it to the client browser as an output stream. Socket programming is used at the bottom of Web server software.

Web Server Software

Manufacturers

Iis

Microsoft

Tomcat

Apache Open-Source server

Web Logic

BEA

Web Sphere

Ibm

Jboss

RedHat

1 Concept of the Web

Web is a Web page. So to develop a Web site needs to start with the development page. Html+css+javascript

2 Concepts of static and dynamic

Static Web page is the source code of each view page if not mutable is static Web page.

Dynamic Web page is the source of each page to see if the variable is a static Web page.

Html+css+javascript+flashà Static

JSP, servlet technology à dynamic

3 Concept of software architecture

Software architecture is a way to deploy software after software software.

CS Structure: Client/server client/server such as: QQ

To download the installation client program. And the data needs to be sent to the server.

Cons: Upgrading

BS structure Browser/server browser/server such as: Web QQ

No additional download client is required, only one browser is required.

Pros: No installation needed and no upgrade required

The site belongs to the BS structure. Thin client program.

Tomcat Server

Tomcat was developed by the Apache Open source organization using the Java language and therefore runs at the time of the JRE. But developers can configure the JDK directly.

1. Download

Http://www.apache.org Tomcat

2. Installation

Direct decompression (green version)

3. Configuration

root directory of the JAVA_HOME=JDK

4. Testing

Go to the installed Bin directory Àstartup.bat

Open Browser Input http://127.0.0.1:8080/visible

Javase Learning Notes XPath introduction with Web server (8)

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.