Tag:Front end
Article From:https://www.cnblogs.com/aland-1415/p/9065337.html

1. Xpath

XPath It is a language for finding information in XML documents; XPath is the main element in XSLT. XPath is the W3C standard.
1、Seven types of nodes: elements, properties, texts, namespaces, processing instructions, annotations, and document nodes;
2、Node relationship (axis)

    parent               The parent node of the current node;Child all the child nodes of the current node;Ancestor all the parent nodes of the current node (father, grandfather...);Ancestor-or-self all the superior nodes and nodes of the current node.Descendant all the lower nodes of the current node (son, sun...);DescendaNt-or-self all the lower nodes of the current node and themselves.Preceding-sibling all the peer nodes before the current node;Following-sibling current nodeAfter all the peer nodes;Following all nodes after the current node;Preceding all nodes before the current node;NamespAce all namespace nodes of the current node;Attribute all attributes of the current node;Self current node; 

3、Select the node method:

    nodeName         Select all of the nodes of this node;/ selected from the root node;/ / select nodes in the document from the matching selection of the current node without considering their location;.Select the current node;.. Select the parent node of the node;@ select the attribute;*Match any element node;* matches any attribute nodes;Node () matches any type of node;Name1|name2Select all Name2 and name1 elements;


A node for finding a particular node or containing a specified value. The predicate is enclosed in square brackets.

    nodeName[1]            Select the first element of nodeName;NodeName[last ()] select the last element.NodeName[position ()<3] Select the first two elements;NodeName[@lang] selects the nodeName element with lang attribute.NodeName[@lang='eng']  Select the element of the attribute Lang with a value of Eng;NodeName[price>30]     Select all nodeName elements whose price elements are greater than 30;


+,-,*,div(Mod =, =, =, =, < < =, > > =, or, and


Two, XQuery

1、XQuery The role of XML is similar to the role of SQL in the database, which is used to query XML data and can be used to query any XML form of data (including a database).
2、XQueryUse the predicate to limit the data extracted from the document;
3、XQuerySensitive to case sensitive, strings can be used with single quotation marks or double quotes.
4、The variable is defined by the $and following a name.
5、 :Notes:
6、General comparison: =, =, < < =, > > =; =;
    Comparison of values: EQ, NE, lt, Le, GT, GE
7、doc(“name.xml”)        This function is used to extract data from XML documents.
    Query example: Doc (“books.xml”) /bookstore/book[price> 30]/title for all title elements under the bookstore element, and the value of the price element is greater than 30;
    Sort by using FLWOR (for let where where order by: return):
    for $x in doc(“books.xml”)/bookstore/book
    where $x/price>30
    order by $x/title
    return $x/title    
8、The data () function is used to display the acquired data.
    Insert a sample of the elements that are querying to the HTML element:

        for $x in doc("books.xml")/bookstore/book
        order by $x/title
        return <li>{data($x/title)}. Category: {data($x/@category)}</li>

9、Self built function format
    declare function Prefix: name ($para as datatype)
    AS Return data type
    {    }


Three, DTD

1、DTD(The role of document type definition is to define the legitimate building blocks of XML documents, which can be declared in XML documents or can be used as an external reference.
2、Modules of all XML documents: elements, attributes, entities, PCDATA, CDATA
3、Entity reference: & lt, & gt, & amp, & quot, & apos
4、Element declaration:

    <!ELEMENT element-name category>    Or <! ELEMENT element-name (element-content) ><! ELEMENT element-name EMPTY>       Empty element<!ELEMENT element-name(#PCDATA)>    Only the elements of the PCDATA<!ELEMENT element-name ANY)>        Elements with any content<!ELEMENT element-name (childname1,...)>        Elements with subelements<!ELEMENT element-name (childname+)>            The subelement appears at least once<!ELEMENT element-name (childname*)>            Subelements appear once or more<!ELEMENT element-name (childname?)>            The subelement appears 0 times or one time<!ELEMENT element-name (childname1|childname2)> or

5、Attribute declaration
    <!ATTLIST element-name attribute-name attribute-type attribute-value>
    Attribute type (attribute-type):

    CDATA            Character data(va1|va2|...)    enumerationID's unique IDID with a IDREF value as another elementA list of IDREFS values of IDNMTOKEN's legitimate XML nameNMTOKENS legal list of XML namesENTITY entityENTITYSEntity listThe name of the NOTATION symbolThe xml: value is a predefined XML value

    Attribute value (attribute-value):

    A default value given for a value#REQUIRED must be filled in#IMPLIED is not requiredThe #FIXED value attribute value is fixed

6、Entity (a variable used to define shortcuts that reference ordinary text or special characters, and entity references are references to entities).
    Entities can be declared internally and externally

    <!ENTITY entity-name “entity-value”>    Internal statement
    <!ENTITY entity-name SYSTEM “URL”>        External statement
    <!ENTITY writer “This is a writer”>
    <!ENTITY copyright “I do not care what it is”>

7、Verification (JavaScript)

    var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
    xmlDoc.validateOnParse="true";    //The value is set to false to close the validation

    document.write("<br />Error Code: ");
    document.write("<br />Error Reason: ");
    document.write("<br />Error Line: ");


Link of this Article: Xpath,XQuery,DTD

Leave a Reply

Your email address will not be published. Required fields are marked *