Use XPath in dom4j

Source: Internet
Author: User



Use XPath in dom4j
Original zergling (Participation score: 48, expert score: 80) published: Update: Version: 1.0 read:2623Times

Import Java. util. iterator;
Import Java. util. List;

ImportOrg. dom4j. Attribute;
ImportOrg. dom4j. Document;
ImportOrg. dom4j. extends entexception;
ImportOrg. dom4j. Io. saxreader;

/**
* @ Author
* <A href = "mailto: jdcyang@yahoo.com.cn"> Liu Yang </a>
* 16:18:27
*/

Public ClassExample4 {

Public Static Void Main (string [] ARGs ){
Example4 example4 = New Example4 ();
Saxreader reader = New Saxreader ();
Document document;
Try {
Document = reader. Read ("address1.xml ");
Example4.query (document );
} Catch (Incluentexception e ){
// Todo auto-generated Catch Block
E. printstacktrace ();
}
}
Public Void Query (document ){
List list = Document. selectnodes ("// phone/@ Type ");
For (Iterator iter = List. iterator (); ITER. hasnext ();){
Attribute attribute = (attribute) ITER. Next ();
String type = attribute. getvalue ();
System. Out. println (type );
}

}
}

Copyright Notice to the author
This article ArticleIs it helpful to you? Vote: Yes NoVoting Result: 1 0


Reviewer:JfmlParticipation score: 616 expert score: 530 from: Hangzhou Posting time:
Dom4j is much easier to use.

It's just not a W3C Standard Interface

It seems a little "independent"

Reviewer:JavamonkeyScore: 527 expert score: 540 from sanlihe, Haidian District, Beijing Posting time:
JDOM now supports this function
I don't know who is better at it? Better standards

Reviewer:JfmlParticipation score: 616 expert score: 530 from: Hangzhou Posting time:
JDOM updates are too slow.

Not as powerful as dom4j

Despite compliance with W3C standards

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.