Document --> XML message transmission and parsing, simple example

Source: Internet
Author: User
Import Java. io. stringreader; import Org. dom4j. document; import Org. dom4j. extends entexception; import Org. dom4j. export enthelper; import Org. dom4j. element; import Org. dom4j. io. saxreader; public class Testa {public static string test () {document = incluenthelper. createdocument (); element = document. addelement ("aaaa"); element ele1 = element. addelement ("BBBB"); element ele2 = element. addelement ("CCCC"); ele1.addtext ("1"); ele2.addtext ("hello"); Return document. asxml ();} public static void main (string [] ARGs) {string test = test (); system. out. println (TEST); stringreader = new stringreader (TEST); saxreader reader = new saxreader (); document DOC = NULL; try {Doc = reader. read (stringreader);} catch (incluentexception e) {e. printstacktrace ();} element = Doc. getrootelement (); string resultcode = element. elementtext ("BBBB"); string resultmsg = element. elementtext ("CCCC"); system. err. println ("[AAAA]" + resultcode); system. err. println ("[BBBB]" + resultmsg );}}

Result:

<? XML version = "1.0" encoding = "UTF-8"?> <AAAA> <BBBB> 1 </BBBB> <CCCC> Hello </CCCC> </AAAA> [AAAA] 1 [BBBB] Hello

 

Document --> XML message transmission and parsing, simple example

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.