XML tree (1) based on the Java implementation of a saved state database-WebLogic, including some basic questions, very detailed.

Source: Internet
Author: User
Tags definition key words query xsl
web|xml| Generating xml| Data | database | Problems generating XML trees from a database with Java implementation of a saved state
Directory
0. Key words Note 1
1. Objective 1
2. Design Idea 1
3. Implementation Overview 1
4. Implementation Step 2
4.1.XML Document Structure Definition 2
4.2. Structure definition of data table 4
4.3. Construct the servlet 4 that generates XML
4.4. Construct an XSL template that displays a tree structure 8
4.5. Construction build Click on the tree XML display verbose node content of the servlet 12
Construction of the session bean called by 4.6.Servlet 13
Communication between 4.7.Servlet 15
5. Where improvements are needed 16
6. Appendix 16
6.1.Servlet Release 16
6.2.SessionBean Release 17
6.3. Source code 18
6.3.1.ResultEdit Sessionbean source code and related documents 18
6.3.2.Servlet Source 23
6.3.3.XSL Source 31

0. Key word annotations
Branches and leaves: in the tree expression, there are two different structures of nodes, they have the function is not the same, with the next level of nodes called the branch, the node without the next level node is called the leaf
1. Objective
In order to implement the rights management of interface elements in different modules, it needs to be tree-graded, the tree-type display of the original applet construction is not recommended because of the speed and structure of the display, and with the strong support of XML technology and browser, The use of XML and related technology to achieve tree structure display can also meet the requirements of speed and structure, in this context, the use of XML tree to replace the implementation of the applet tree is a more excellent method.
2. Design Ideas
Extracts the tree's related parameters from the database tree table, generates the data-related tree structure, and behaves as a scalable tree in the browser. Control the shape of a tree by inserting a delete modification record in the database.
3. Overview of Implementation
First from a terminal to display the tree data of the database records of the query, the result set of the query into the session bean rowset, the user through the servlet to obtain the session Bean in the session of the rowset record of the tree constructed by the servlet , the document for the tree is in XML format, and the XML document is ultimately displayed by the client browser by using an XSL-constructed template, which requires support for XML and XSL browsers, so it is platform-dependent in the current situation. Passing the session bean on multiple pages at the same time by putting the handle of the session bean into session, and then getting the handle of the session bean by calling session when the servlet needs it.
The page flow is as follows:



4. Implementation steps
4.1.XML Document Structure definition
It is important to define the elements of an XML document and its attributes, because the level of the tree, the information of the nodes, and all the needs are contained in the XML definition, and the XML elements are defined, and the data table structure is almost defined.
From the page requirements, for a node, the required attributes have, node display characters, the leaf has a hyperlink, frame target, for the composition of the tree need also, the node serial number, level, parent node. So you can set up a node like this:
The <!-node ends with the <node> start,</node>, and the middle is the attribute of a node-->
<node>
<id>14</id><!-serial number, unique identification of each node-->
<layer>1</layer><!-levels, starting with the first level of 0, and so forth-->
<name>n14</name>
<value> node 14</value><!-The string displayed on the page-->
<father>6</father><!-The parent Node ID of the current node, the node with no parent node is set to 0-->
<target>mainframe</target><!-When the node is a leaf, the value is not empty, and the value is the target frame of the link-->
</node>

Although the hierarchy of the tree is reflected in the attribute description of the node, the parent-child relationship of the node, however, because of the reasons for the support of the template for XSL, such as easy retrieval, the hierarchy of the tree needs to be embodied in the form of nodes nesting in XML. The following code shows a leaf with ID 15 and a branch with ID 16 under the node with ID 14, and a tree with ID 17 under the branch with ID 16. This occurs as a nested form.
<node>
<id>14</id>
<layer>1</layer>
<name>n14</name>
<value> node 14</value>
<father>6</father>
<target> </target>
<node>
<id>15</id>
<layer>2</layer>
<name>n15</name>
<value> node 15</value>
<father>14</father>
<target>mainFrame</target>
</node>
<node>
<id>16</id>
<layer>2</layer>
<name>n16</name>
<value> node 16</value>
<father>14</father>
<target></target>
<node>
<id>17</id>
<layer>3</layer>
<name>n17</name>
<value> node 17</value>
<father>16</father>
<target>mainFrame</target>
</node>
</node>
</node>
The outermost layer of an XML document is the root of <project> and </project>. Gives the DTD for this XML parameter:
<! ELEMENT Project (name, node+) >
<! ELEMENT order (#PCDATA) >
<! ELEMENT name (#PCDATA) >
<! ELEMENT layer (#PCDATA) >
<! ELEMENT node (layer+, order+, name+, value+, node*) >
<! ELEMENT value (#PCDATA) >

The following illustration shows the full expansion of the final display of the XSL template on the browser, and the corresponding XSL template needs to be configured as shown in the following illustration.

(Figure 1)

4.2. Structure Definition of data table
This defines a model datasheet that can be used to generate an XML tree whenever any result set conforms to the field requirements of the following table.
The attributes of the nodes defined in the XML document structure can also be reflected in the data table, and the fields in the table should have:
Name Type Size Null Explain
Id Number 3 No.
Layer Number 2 No level
Name VARCHAR2 5 No.
Value VARCHAR2 No display character
Father number 3 No parent Node ID
Target VARCHAR2 Yes goal framework
Href VARCHAR2 Yes linked objects



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.