Working with DOM4J XML (bottom)

Source: Internet
Author: User
Tags xpath

Record some general usage of XPath, memo.

1 //3. XPath Understanding (used to select elements in XML, like jquery selectors)2                 //3.1 Path3Node Node1 = Root.selectsinglenode ("/person"); 4 System.out.println (Node1.asxml ());5                 6                 //3.2 "@" Select Node properties (take attributes generally with selectSingleNode)7Node node4 = Root.selectsinglenode ("//person"). selectSingleNode ("@name");8 System.out.println (Node4.asxml ());9             Ten                 //3.3 "[]" can be used as a filter or as subscript Onelist<node> nodes1 = Root.selectnodes ("//person[@cls! = ' 04 ']");//find node named person from current path and the CLS attribute value is not 04 A                  for(Node tmpnode:nodes1) -                 { - System.out.println (Tmpnode.asxml ()); the                 } -             //3.4 Summary: ---------Path------------------- -                     // "//Person ""//"indicates the start of the current node (ignoring the intermediate path) to find the node in the descendant node that has no person +                     // "//Persons//a "of two// -                     // "..                                  /.." Parent nodes of parent node +                     //"/person" from the root node (do not ignore the intermediate path, the first level to look down) ... Not only can not find, but also affect the execution of subsequent code.  A---------Filter AND operator------ at                     // "//Person[a] "//from the current path, node is named person and contains a child node -                     // "//person[@id] "//from the current path, node is named person and has an id attribute -                     // "//person[@age >=24] "=! = > >= < <= (but *=, $=, ^=, ~=, etc. are not supported) -                     // "//person[@age >=24 and @age <30] "and -                     // "//person[@age >=24][@age <30] "action Ibid. -                     // "//person[@age >26 or @age <20] "or in                     // "//Person[not (@age <25)] "non- -                     // "//Persons/dog |//Persons/person "Returns the set of two lists ("//Persons/dog and//Persons/person "does not reach such an effect) to----------Subscript------------ +               // "//person[2] "takes the 2nd node in the matching node (subscript starting from 1) -               // "//person[last ()-1] "Take the second from the bottom of the the  *-----------Wildcard characters----------- $               // "//person/@name "matches the name of all person nodesPanax Notoginseng               // "//Persons/person "matches all person child nodes under persons -               // "//persons/* "wildcard character, matching all child nodes under persons-----------function----------------- the               //"/node ()" matches all nodes under the root node (including text nodes and note nodes) (Note the difference from "/*" ) +               // "//Dog/text () "matches the text under the dog node A               // "//Child::node () "Recursively all descendant nodes (containing text nodes and comment nodes) starting at the current position the               // "//Child ::* "recursively all descendant nodes starting from the current position +  ---------------------------with namespaces $               // "//namespace::* "Output all the namespace, there are duplicates!  $               // "//*[local-name () = ' person '] "matches the node local-name for person, such as???:p Erson -               // "//Mt:person "Just take the namespace. -               //"/cumt:classes/mc:persons/mt:person"

Note: descendant nodes and child nodes are not the same thing, descendant nodes also include child nodes of child nodes ...

Working with DOM4J XML (bottom)

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.