The arrangement of XML knowledge points--from Guangzhou chuan Chi Wang Teacher

Source: Internet
Author: User
Tags cdata naming convention
Xml Knowledge Summary

Structure of XML

Document declaration:

element: (Tag tag)

Element properties

An element can have more than one property

Attribute values must be quoted in quotation marks ( single or double quotation marks ) .

The naming convention for property names is the same as for element naming conventions

The attributes in the element are not allowed to be duplicated

The information represented by the Tag property can also be changed to describe it in the form of a child element.

Processing instructions

Must start with " ?> " as the end

XML Directives

Xml-stylesheet Directive

Cases:

Comments:

Comments can be displayed in the browser

XML declaration cannot be preceded by comments , comments cannot be nested

CDATA Section

Grammar:

</p><p>Content</p><p>

XML DTD document constraints

The constraint document defines the element names, attributes, and the order in which the elements are allowed to appear in the XML .

DTD constrained Document classification

Internal DTD

root element [

DTD Constraints

]>

External DTD

root element SYSTEM " path to external DTD " >

Public DTD

root element Public "DTD Identity name "" Public DTD of the URI ">

DTD constrained Authoring

Defining Elements ( tags or tags )

Element name element type >

Element type

(#PCDATA): The type contains no character data and cannot contain child elements

EMPTY: The type cannot contain child elements or text and can have attributes

Any: The element contains so content (for the root element)

( child element ) : Define child elements to occur only once

( child element 1, child element 2, ...): elements appear in the specified name and order

( child element +) : Current element appears 1+ Times

( child element *) : Current element appears 0+ Times

( child element?) ) : Current element query 0 or 1 times

( child element 1 | child elements 2) : Mutually exclusive element, only select one

Defining properties

Basic syntax:

Element Name Property Name property type default value >

Property type

CDATA: Character or number (text type)

(En1|en2|en ...) : Enum type

ID: attribute unique

IDREF: referencing the defined ID attribute

#REQUIRED: required (default value)

#IMPLIED: Optional

#FIXED: Fixed value

Value: Use default values directly

Defining entities

Referencing entities

Basic syntax:

entity name " entity value " >

Reference syntax: [ use in XML ]

& entity name ;

Parameter entity [ parameter entity must be defined in an external DTD , used in an external DTD ]

Basic syntax:

Entity name " entity value " >

Reference syntax:

% entity name ;

PHP parsing XML data

PHP DOM Model parsing XNL

PHP DOM class

DOMDocument: document class

Domnodelist: Node List class

Domnode: Node class

DomElement: Node class

DOMDocument class:

Basic syntax:

Domdocument::__construct (String $version, String $encoding) {}

use of the Load method

Domdocument_obj->load (' Xml_filename.xml ');

use of the Item method:

Domdocument_obj, item (int index);

Case: PHP DOM query Operation

"1" opens up memory space to form " face "

$dom = new DOMDocument (' 1.0 ', ' utf-8 ');

"2" loads the XML file into memory, forming the Dom tree

$dom->load (' Test.xml ');

"3" gets siblings of sibling nodes, forming a string

$names = $dom->getelementsbytagname (' element name ');

"4" Gets the node name for King Sledgehammer's name node information, the so-called Dot

$name = NodeValue, $names;

The above code simplifies:

$dom->getelementsbytagename (' name ')->item (0)->nodevalue;

PHP DOM Property Manipulation

# Determines whether a node has a specified property

BOOL Domelement::hasattribute (string $name);

# to determine if a node has a specified property

BOOL Domnode:: HasAttributes (void);

# Gets the value of the specified property of a node

String Domelement::getattribute (string $name);

PHP DOM Additions and deletions to check the operation

PHP DOM increment operation:

How to create a new node:

DOMDocument:: createelement (string name []);

Append new node:

DOMDocument:: AppendChild (Domnode $newnode);

Save operation:

DOMDocument:: savexml (filename);

PHP DOM Delete operation:

To remove a node operation:

Domnode:: RemoveChild (Domnode $nodeName);

PHP DOM change operation:

Update node Operations:

/**

* @param string $newNode The updated node

* @param string $oldNode the old node

*/

Domnode:: ReplaceChild (Domnode $newNode, Domnode $oldNode);

PHP DOM Property Operations:

To add a property to a node:

/**

* @param string to add the name of the property

* @param The value of the string property

*/

SetAttribute (String $name, string $value);

Update Node Properties:

/**

* @param string The name of the property to be updated

* @param The value of the string property

*/

SetAttribute (String $name, string $value);

Remove the properties of the specified node:

/**

* @param string The name of the property to delete

*/

Removerattribute (string $name);

SimpleXML parsing XML

Reading XML data

Basic syntax:

/*

* @param string $filename the XML file name to load

*/

SimpleXMLElement simplexml_load_file (string $filename);

/**

* @param string $str xml character content that is already defined

*/

SimpleXMLElement simplexml_load_string (string $str);

Querying XML data

get XML data with the Children () method

Get by using the foreach () method

Direct Access via $xml->result[0]->nodename

The addition of XML elements

/**

* @param string $name The name of the element to be added

* @param string $value set the value

*/

Simplexmlelement::addchild (String $name [, String $vaule]);

# After the add is complete, save it

/**

* @param string $filename the saved XML file name

*/

SimpleXMLElement:: Asxml (String $filenmae);

query for XML properties

/**

* @param string Attr_name The name of a property added

*/

SimpleXMLElement:: attributes ()->attr_name;

Adding XML attributes

/**

* @param string $name The name of the property to be added

* @param string $value property value

*/

Smplexmlelement::addtribute (String $name, [string $value [, String $namespace]

Xpath queries XML data

Absolute path

Relative path //

Asterisk * query Instructions

Bracket expression

@ Property

The above on the introduction of XML knowledge points carding-organized from the Guangzhou Chi Wang teacher, including the content, I hope the PHP tutorial interested in a friend helpful.

  • Related Article

    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.