Introduction to XMLHTTP and XMLDOC (below)

Source: Internet
Author: User
Tags tagname xsl

Next, write the method in the last XMLDOC. The main methods of Document are:

1. abort
2. appendChild
3. cloneNode
4. createAttribute
5. createCDATASection
6. createComment
7. createdocument. ragment
8. createElement
9. createEntityReference
10. createNode
11. createProcessingInstruction
12. createTextNode
13. getElementsByTagName
14. hasChildNodes
15. insertBefore
16. load
17. loadXML
18. nodeFromID
19. parsed
20. removeChild
21. replaceChild
22. selectNodes
23. selectSingleNode

24. transformNode

 

Abort Method
-------------
The abort method cancels an asynchronous download in progress.

Basic Syntax:
Xmldocument. abort ();
Note: If this method is called during asynchronous download, all resolution actions will stop,
Files in the memory will be released.

AppendChild Method
------------------
Add a node as the final sub-node of the specified node.

Basic Syntax:
Xmldocument. ode. appendChild (newChild );
Note: newChild is the address for appending subnodes.
Example:
DocObj = xmlDoc.doc ument. lement;
Alert (docObj. xml );
ObjNewNode = docObj.appendChild(xmlDoc.doc ument. lement. firstChild );
Alert (docObj. xml );

CloneNode Method
---------------
Create a copy of the specified node.

Basic Syntax:
Xmldocument. ode. cloneNode (deep );
Note: deep is a Boolean value.
If this parameter is set to true, the node copies all nodes developed from the specified node.
If it is false, only the specified node and its attributes are copied.
Example:
CurrNode = xmlDoc.doc ument. lement. childNodes. item (1 );
ObjClonedNode = currNode. cloneNode (1 );
Alert (objClonedNode. xml );

CreateAttribute Method
------------------------
Creates an attribute with a specified name.

Basic Syntax:
Xmldocument. createAttribute (name );
Description: name is the name of the property to be created.
Example:
ObjNewAtt = xmlDoc. createAttribute ("encryption ");
Alert (objNewAtt. xml );

CreateCDATASection Method
------------------------
Create a CDATA that contains specific data.

Basic Syntax:
Xmldocument. createCDATASection (data );
Note: date is a string that contains information stored in CDATA.
Example:
ObjNewCDATA = xmlDoc. createCDATASection ("This is a CDATA Section ");
Alert (objNewCDATA. xml );

CreateComment Method
-------------------
Creates an annotation that contains the specified data.

Basic Syntax:
Xmldocument. createComment (data );
Note: data is a string that contains information that is placed on the annotation.
Example:
ObjNewComment = xmlDoc. createComment ("This is a comment ");
Alert (objNewComment. xml );

Createdocument. ragment Method
-----------------------------
Creates an empty File Fragment object.

Basic Syntax:
Xmldocument. createdocument. ragment ();
Note: A New File segment is created but not added to the file tree.
To add fragments to the file tree, you must use the insert method,
For example, insertBefore, replaceChild, or appendChild.
Example:
ObjNewFragment = xmlDoc. createdocument. ragment ();
Alert (objNewFragment. xml );

CreateElement Method
--------------------
Creates an element with a specified name.

Basic Syntax:
Xmldocument. createElement (tagName );
Description: tagName is a case-sensitive string used to specify the name of a new element.
Example:
ObjNewElement = xmlDoc. createElement ("");
Alert (objNewElement. xml );

CreateEntityReference Method
-----------------------------
Create an object with the specified name.

Basic Syntax:
Xmldocument. createEntityReference (name );
Description: name is a case-sensitive string used to specify the name of a new object reference.
A new object reference is created but not added to the file tree.
To add object references to the file tree, you must use an insert method,
For example, insertBefore, replaceChild, or appendChild.
Example:
ObjNewER = xmlDoc. createEntityReference ("eRef ");
Alert (objNewER. xml );

CreateNode Method
----------------------
Create a new node with a specified type, name, and namespace.

Basic Syntax:
Xmldocument. createNode (type, name, nameSpaceURI );
Note:
Type is used to confirm the node type to be created,
Name is a string to confirm the name of the new node. the prefix of the namespace is optional.
NameSpaceURI is a string that defines the URI of a namespace.
If the prefix is included in the name parameter, this node is created with the specified prefix in the nameSpaceURI document.
If the prefix is not included, the specified namespace is considered as the preset namespace.
Example:
ObjNewNode = xmlDoc. createNode (1, "","");
Alert (objNewNode. xml );

CreateProcessingInstruction Method
--------------------------------
Creates a new processing command that contains the specified target and data.

Basic Syntax:
Xmldocument. createProcessingInstruction (target, data );
Note:
Target is a string that represents the target, name, or processing command.
Data indicates the value of the Processing Command.
A New Processing Command is created but not added to the file tree.
To add processing commands to the file tree, you must use the insert method,
For example, insertBefore, replaceChild, or appendChild.
Example:
ObjNewPI = xmlDoc. createProcessingInstruction ('xml', 'version = "1.0 "');
Alert (objNewPI. xml );

CreateTextNode Method
------------------------
Create a new text node and contain the specified data.

Basic Syntax:
Xmldocument. createTextNode (data );
Note:
Data is a string representing the new text node.
A new text node is created but not added to the file tree.
To add a node to the file tree, you must use the insert method,
For example, insertBefore, replaceChild, or appendChild.
Example:
ObjNewTextNode = xmlDoc. createTextNode ("This is a text node .");
Alert (objNewTextNode. xml );

GetElementsByTagName Method
-----------------------------
Returns the element set with the specified name.

Basic Syntax:
ObjNodeList = xmldocument. getElementsByTagName (tagname );
Note:
Tagname is a string that represents the name of the element volume found.
Use tagname "*" to return all elements found in the file.
Example:
ObjNodeList = xmlDoc. getElementsByTagName ("*");
Alert (objNodeList. item (1). xml );

Haschildnodes Method
----------------------
If the specified node has one or more subnodes, the return value is true.

Basic Syntax:
Boolvalue = xmldocument. ode. hasChildNodes ();
Note: If this node has a subnode, the return value is true. Otherwise, the return value is false.
Example:
Boolvalue = xmlDoc.doc ument. lement. hasChildNodes ();
Alert (boolvalue );

InsertBefore Method
---------------------
Insert a subnode before the specified node.

Basic Syntax:
Objdocument. ode = xmldocument. ode. insertBefore (newChild, refChild );
Note:
NewChild is an object that contains the new subnode address,
RefChild is the address of the reference node.
The new subnode is inserted before the reference node.
If the refChild parameter is not included, the new subnode is inserted at the end of the subnode list.
Example:
ObjRefNode = xmlDoc.doc ument. lement;
Alert (xmlDoc. xml );
ObjNewNode = xmlDoc. createComment ("This is a comment ");
XmlDoc. insertBefore (objNewNode, objRefNode );
Alert (xmlDoc. xml );

Load Method
--------------
Indicates the file to be loaded from the specified position.

Basic Syntax:
Boolvalue = xmldocument. load (url );
Note:
The url contains the string of the URL of the file to be loaded.
If the file is successfully loaded, the return value is true.
If loading fails, the returned value is false.
Example:
Boolvalue = xmlDoc. load ("Lst. xml ");
Alert (boolvalue );

LoadXML Method
----------------
Load an XML file or a string segment.

Basic Syntax:
Boolvalue = xmldocument. loadXML (xmlString );
Description: xmlString is a string containing an XML text code.
This string can contain the entire file or just a file segment.
If the file is successfully loaded, the return value is true.
If loading fails, the returned value is false.
Example:
XmlString = "<GREETING> <MESSAGE> Hello! </MESSAGE> </GREETING> ";
Boolvalue = xmlDoc. loadXML (xmlString );
Alert (boolvalue );

NodeFromID Method
------------------
Return the node whose ID matches the specified value.

Basic Syntax:
Xmldocument. ode = xmldocument. nodeFromID (idString );
Note:
IdString is a string containing the ID value.
The node must be of the ID type.
If yes, an object is returned. If the operation fails, null is returned.
Example:
Objdocument. ode = xmlDoc. nodeFromID ("");
Alert (objdocument. ode );

Parsed Method
-------------
It verifies that the specified node and its derived sub-nodes (descendants) have been parsed.

Basic Syntax:
Boolvalue = xmldocument. ode. parsed ();
Note:
If all nodes have been parsed, the return value is true;
If any node is not parsed, the returned value is false.
Example:
CurrNode = xmlDoc.doc ument. lement. childNodes. item (0 );
Boolvalue = currNode. parsed ();
Alert (boolvalue );

RemoveChild Method
-------------------
The specified node is removed from the node list.

Basic Syntax:
Objdocument. ode = xmldocument. ode. removeChild (oldChild );
Note: oldChild is a Node object that contains the node to be removed.
Example:
ObjRemoveNode = xmlDoc.doc ument. lement. childNodes. item (3 );
Alert (xmlDoc. xml );
XmlDoc.doc ument. lement. removeChild (objRemoveNode );
Alert (xmlDoc. xml );

ReplaceChild Method
--------------------
Replace the specified old subnode as the new subnode.

Basic Syntax:
Objdocument. ode = xmldocument. ode. replaceChild (newChild, oldChild );
Note:
NewChild is the object that contains the new subnode.
If this parameter is null, the old subnode is removed and not replaced.
OldChild is the object that contains the old child node.
Example:
ObjOldNode = xmlDoc.doc ument. lement. childNodes. item (3 );
ObjNewNode = xmlDoc. createComment ("I 've replaced the BCC element .");
Alert (xmlDoc. xml );
XmlDoc.doc ument. lement. replaceChild (objNewNode, objOldNode );
Alert (xmlDoc. xml );

SelectNodes Method
--------------------
Returns all nodes that match the provided pattern.

Basic Syntax:
Objdocument. odeList = xmldocument. ode. selectNodes (patternString );
Note:
PatternString is a string containing the XSL style.
This method will return the node list object, including the nodes that match the style.
If no matching node exists, an empty list is returned.
Example:
ObjNodeList = xmlDoc. selectNodes ("/");
Alert (objNodeList. item (0). xml );

SelectSingleNode Method
--------------------------
Returns the first conforming node.

Basic Syntax:
Objdocument. ode = xmldocument. ode. selectSingleNode (patternString );
Note:
PatternString is a string containing the XSL style.
This method returns the first conforming Node object. If no conforming node exists, null is returned.
Example:
ObjNode = xmlDoc. selectSingleNode ("EMAIL/BCC ");
Alert (objNode. xml );

TransformNode Method
----------------------
Use the provided style sheet to process the node and Its subnodes.

Basic Syntax:
StrTransformeddocument = xmldocument. ode. transformNode (stylesheet );
Note:
Stylesheet is an XML file or segment that contains the XSL elements responsible for node conversion.
This method returns a string containing the conversion result.

Example:
Var style = new ActiveXObject ("Microsoft. XMLDOM ");
Style. load ("Lst. xsl ");
StrTransform = xmlDoc.transformNode(style.doc ument. lement );
Alert (strTransform );

Event of the Document Object

The following lists the available events of the document Object:
1. Ondataavailable
2. Onreadystatechange

Ondataavailable event
----------------------
This event is triggered when the XML file is valid.

Basic Syntax:
This event can be handled in the following three ways:
. Inline: <element ondataavailable = handler>;
. Event property: object. ondataavailable = handler;
. Named script: <script for = object EVENT = ondataavailable>;
Note: An ondataavailable event is triggered when valid data is obtained.
This technology does not indicate how much data is valid in this file.
Example:
XmlDoc. ondataavailable = alert ('data is now available .');

Onreadystatechange event
------------------------
This event is triggered when the content of the readyState attribute changes.

Basic Syntax:
This event can be handled in the following three ways:
. Inline: <element onreadystatechange = handler>;
. Event property: object. onreadystatechange = handler;
. Named script: <script for = object EVENT = onreadystatechange>;
-
Note:
The onreadystatechange event is triggered when the content of the readyState attribute changes,
However, this event does not indicate the status of "ready.
You must use the readyState attribute to obtain the current state.
Example:
XmlDoc. onreadystatechange =
Alert ("The readyState property is" + xmlDoc. readyState );

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.