20150202--xml under 01

Source: Internet
Author: User

Universal data transfer format under XML

Directory

Universal data transmission Format XML ..... ..... ..... ....................... ..... ..... ..... ..... ..... .............. .......... 1

First, PHP XML parsing principle ..................................................................................................... 3

1. Why XML parsing is required ..... ..... ..... ..... .................. ..... ..... ..... ..... ..... ............. .......... 3

2, how to do XML parsing (PHP) ...... ..... ..... .............. ....... ..... .................. ......... 3

Second, PHP DOM parsing xml .................................................................................................... 3

1. PHP DOM Model ...................................................................................................... 3

1) The operation mechanism of the program: ..... .... ..... ..... ................. ..... ..... ..... ..... .............. ........... 3

2) XML in the in-memory parsing process: ..... ..... ..... ............ ....... ..... ....................... 4

3) PHP Dom three key words ("Face", "string", "point") ... ..... ..... ..... ..... ..... ..... ..... ..... ........... 4

4) PHP parsing xml Four-step walk: ..... ..... ..... ............... ....... ..... ................. ......... 4

A) open up the memory space and form "noodles" ...... ..... .............. ....... ..... ................. ......... 5

b) Load the XML file into memory, form the DOM tree structure ... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ....... 6

c) Find siblings of sibling nodes, the formation of "strings" ... .... ... .... ... .... ..... ..... ..... ..... ..... ..... ..... ..... ... and ..... ..... ... and .... ..... ...... 6

d) Get sibling nodes and output their values ..... ..... .............. ....................... ........ 7

2, PHP DOM Query and traversal ..... ..... ..... ..... ..... ..... ............ ..... ..... ..... ..... ..... ............. .......... 8

3. PHP Dom add Operation ...... ..... .......................... ..... ..... ..... ..... ..... ............... ......... 9

4. PHP Dom Delete operation ...... ..... ........................ ..... ..... ..... ..... ..... .............. .......... 11

5. PHP Dom Update operation ...... ..... ........................ ..... ..... ..... ..... ..... .............. .......... 12

The value update operation four steps away: ...... ..... ..... ................... ..... ..... ..... ..... .............. ........... 12

Node Update operation six steps away: ....... ..... ..... ................. ....... ..... .................. ......... 13

6. Attribute manipulation ............................................................................................................ 14

1) Adding attributes to the update operation ...... ..... ..... ..... ............ ....... ..... ....................... 14

2) The judgment of the property and the reading operation ..... ..... ..... ..... .......... ....... ..... ....................... 15

3) Remove attributes ..... ..... ..... ..... .......................... ..... ..... ..... ..... ..... ..... ..... ....... .............. 16

Job One: Php+xml writing CRM Customer Relationship Management system ..... ..... ... ..... .... ..... ..... ....., ... and ..... .....????????????? ..... 17

Third, PHP SimpleXML implementation of the XML additions and deletions to the search ........ ......... ....................... ........ 17

1. Load the XML file into the memory and form the SimpleXML object ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ....... 17

2, how to enter the value of the specified text node ..... ..... ............... ....... ..... ................. ......... 18

3, how to traverse the output all data? ................................................................................... 19

4. How to Output properties? ................................................................................................. 20

5, expand the case: Query the weather forecast and give the corresponding suggestions ... ..... ... ..... ..... ..... ..... ...................... 21st

6. SimpleXML Add a node ...... ..... ..... ..... .................. ..... ..... ..... ..... ..... ............. .......... 22

7, simplexml Modify and delete operation ....... ..... ..... ..... ............ ....... ..... ................. ......... 23

Iv. Xpath ....................................................................................................................... 24

1, using the absolute path to query data ...... ..... ..... ................. ..... ..... ..... ................. .......... 24

2, the use of relative path to query data ....... ..... ..... ............... ..... ..... ..... ................. .......... 26

3. Search all data by asterisk * ....... ..... ................... ..... ..... ..... ................. .......... 27

4. Use [] square brackets for conditional query ...... ..... ................. ....... ..... .................. ......... 28

5, through the @ symbol of the property query ....... ..... ..... .............. ....... ..... .................. ......... 28

6. Expand the [] conditional query in XPath ..... ..... ..... ................ ....... ..... .................. ......... 29

V. Case: Online Word Blaster ....................................................................................................... 30

1. Interface design ............................................................................................................ 30

2. Design Database ........................................................................................................ 30

3, back-end system design ..... ..... ..... .... ..... ..... ....... ............. ..... ..... ..... ..... ..... ..... ..... ....... .............. 31

4, the front-desk function realizes: ..... ..... ..... ..... ....... .............. ..... ..... ..... ..... ..... ..... ............ ........... 31

Homework Two: Online word bully ..... ..... .... ..... ....... ....................... ..... ..... ..... ..... ..... ..... ..... ..... ..... ...... ....... ....... 321, PHP XML parsing principle 1, why need XML parsing

2. How to parse XML (PHP)

PHP DOM model for XML parsing (add, modify, delete)

PHP SimpleXML (query) Two, PHP DOM parsing xml 1, PHP DOM model 1) program operation Mechanism:

Regardless of the program (JS, XML) at run time, have to go through the process:

When we send a request to the server through a browser, the system first loads the parsed language into system memory and runs in memory in parsing 2) XML in-memory parsing process:

Description: In the DOM model, the model is divided into two types:

Standard DOM Model (JAVASCRIPT)

Non-standard DOM model (PHP)

Schematic diagram of the model:

3) PHP Dom three key words ("Face", "string", "dot")

4) PHP parsing xml Four-step walk:

1, in memory to open up storage space-"face"

2. Load the XML file into memory and form the DOM tree structure

3, get sibling nodes--"string"

4. Gets the specified text node and reads its value-"point"

Example code:

Php+xml Library Management System

1) Design Database (XML)

A) Create Data.xml as our database

b) Create the root node library

c) Create book sub-nodes and store title, author, Price

2) parse XML data a) open up memory space and form "polygons"

The knowledge points to use:

DOMDocument

Parameter description:

$version: XML version number, with 1.0

$encoding: Encoding format, Utf-8

The results are as follows:

b) Load the XML file into memory to form the DOM tree structure

The knowledge points to use:

Parameter description:

$filename: Name of the XML file to load

c) Find sibling nodes to form "strings"

The knowledge point to use

Domnodelist

Parameter description:

$length: Gets the length of the current string, which is the label of several currently found under the root node

Item (index, default starting from 0): Gets the specified node

getElementsByTagName ()

Parameter description:

$name: To get the name of an element (tag, tag)

d) Get sibling nodes and output their values

The knowledge points to use:

Parameter description:

$index: Gets the specified element by index

Operation Result:

By observing the results of the operation, it is known that the data is returned by the DomElement type, and the manual is used Domnode, why?

A: Mainly because DomElement inherits the Domnode so the return type is used in the manual Domnode

The output results are as follows:

2. PHP DOM Query and traversal

Operating effect:

3. PHP Dom Add operation

Four more steps to go:

1) open up the surface space

2) load XML into memory to form a DOM tree

3) Create the node and append

4) Save the memory data into the XML file

The knowledge points to use:

Parameter description:

$name: Name of the node created

$value: Optional parameter to create the value of the node

Parameter description:

$newnode: New node name appended (requires type DomElement or Domnode)

Parameter description:

$filename: The name of the XML file to save

Example code:

Operating effect:

4. PHP Dom Delete operation

Delete Operation five walk:

1) Open up memory space and form "face"

2) load the XML file into memory

3) Locate the node you want to delete

4) Locate its parent node and remove its specified child node

5) Save the memory data into the XML file

The knowledge points to use:

Parameter description:

$oldnode: The node to be moved out

Example code:

Operation Result:

5. PHP Dom Update operation

There are two types of PHP DOM update operations:

1) value operation, update only the value information of a node (via the NodeValue property setting)

2) node operation requires a specific function assistance to complete (by ReplaceChild method setting) value update operation four steps away:

1) Open up memory space and form "face"

2) load the XML file into memory to form the DOM tree

3) Locate the node you want to update and update its value

4) Save the memory data into the XML file

Example code:

Operation Result:

Node Update operation six walk:

1) Open up memory space and form "face"

2) load the XML file into memory

3) Create a new node

4) Find the old node

5) Locate the parent node and replace the old node with the new node

6) Save the memory data into the XML file

The knowledge points to use:

Parameter description:

$newnode: Create a new node

$oldnode: The old node to update

Example code:

Operation Result:

6, Attribute action 1) Add and update actions for attributes

The knowledge points to use:

The addition of the property to the update operation is the same method setattribute, when the current element has no attributes, the system will automatically add the property, if it already exists, update its value

Parameter description:

$name: Property Name

$value: The value of the property

Example code:

Operating effect:

2) attribute judgment and read operation

BOOL Domelement::hasattribute (String $name): Determines whether the current element has a property

BOOL Domnode:: hasattributes (void): Determines whether the current element has attributes

String Domelement::getattribute (String $name): Gets the attributes of an element

Parameter description:

$name: Property Name

Example code:

Operating effect:

3) Remove attributes

The knowledge points to use:

BOOL Domelement::removeattribute (String $name)

Parameter description:

$name: Name of the property to be moved out

Example code:

Operation Result:

Job One: Php+xml writing CRM Customer Relationship management system

1) to have background login interface and background interface

2) The database is stored using XML files

Config: Save user name and password

3) can enter the background, input customer data

Name, age, industry, address, telephone

4) The user data can also be queried through the list.

20150202--xml under 01

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.