Parsing of XML documents in Java (resolved)

Source: Internet
Author: User

Exercise struts1.2 + hibernate3.1 programming in myeclipse5.1 these two days.


Struts and hibernate have been familiar with the basic syntax and core technologies intermittently over the past year, so they have found an example of RSS online reading.


In the middle, I encountered a problem of parsing RSS XML documents.

The core Parsing Code is as follows:

Public static list parsefeed (string address ){
// System. setproperty ("javax. xml. parsers. documentbuilderfactory", "com.sun.org. Apache. Crimson. JAXP. documentbuilderfactoryimpl ");
//
List <Object> result = new arraylist <Object> ();
//
Documentbuilderfactory DBF = documentbuilderfactory. newinstance ();
System. Out. println ("Factory:" + DBF );
//
Documentbuilder dB;
Document Doc;

Try {
//
DB = DBF. newdocumentbuilder ();
//
// Doc = dB. parse (Address );
Java. Io. File file = new java. Io. File (Address );
Doc = dB. parse (File );
//
Nodelist NL = Doc. getelementsbytagname ("item ");
//
For (INT I = 0; I <NL. getlength (); I ++ ){
Node node = NL. item (I );
Nodelist nl2 = node. getchildnodes ();

Node nodetitle = nl2.item (1 );
Node nodeauthor = nl2.item (2 );
Node nodeurl = nl2.item (3 );
Node nodedescription = nl2.item (4 );

String title = nodetitle. getfirstchild (). getnodevalue ();
String author = nodeauthor. getfirstchild (). getnodevalue ();
String url = nodeurl. getfirstchild (). getnodevalue ();
String description = nodedescription. getfirstchild (). getnodevalue ();

// Construct the item object based on the obtained information
// Item = new item (title, description, author, URL );
// Put the generated item into the result list for returning
// Result. Add (item );
}
}
Catch (parserconfigurationexception e ){
//
E. printstacktrace ();
}
Catch (saxexception e ){
//
E. printstacktrace ();
}
Catch (ioexception e ){
//
E. printstacktrace ();
} Finally {
//
// System. setproperty ("javax. xml. parsers. documentbuilderfactory", "com.sun.org. Apache. xerces. Internal. JAXP. documentbuilderfactoryimpl ");
Return result;
}
// Return result;
}

 

However, null is returned. I have viewed this statement:

Documentbuilderfactory DBF = documentbuilderfactory. newinstance ();

The value of DBF in is:

Com.sun.org. Apache. xerces. Internal. JAXP. documentbuilderfactoryimpl @ 8f4fb3


In the elseif column there is a dedicated discussion of this issue (URL: http://blog.csdn.net/elseif/archive/2005/04/29/367506.aspx)

Unfortunately, I used JDK 1.5.0 _ 06 without a package.

Org. Apache. Crimson. JAXP. documentbuilderfactoryimpl (in my case, the complete path should be com.sun.org. Apache. Crimson. JAXP. documentbuilderfactoryimpl), but this class does not exist. Because the package com.sun.org. Apache. Crimson. * cannot be found at all, I wonder if it is my JDK problem and I am looking for a solution ....

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

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.