Re: XML JDOM problems
Hi all,
Here is the error log:
Error on line 46 of document file:/var/lib/tomcat5/webapps/xml/
data/iP4200_DRV_2.xml: The reference to entity "cmp" must end with the
';' delimiter.
org.jdom.input.JDOMParseException: Error on line 46 of document file:/
var/lib/tomcat5/webapps/xml/data/iP4200_DRV_2.xml: The reference to
entity "cmp" must end with the ';' delimiter.
at org.jdom.input.SAXBuilder.build(SAXBuilder.java:465)
at org.jdom.input.SAXBuilder.build(SAXBuilder.java:810)
at org.jdom.input.SAXBuilder.build(SAXBuilder.java:789)
at canon.xml.servlet.XmlServlet.process(XmlServlet.java:60)
at canon.common.servlet.BaseServlet._process(BaseServlet.java:81)
at canon.common.servlet.BaseServlet.doGet(BaseServlet.java:90)
at javax.servlet.http.HttpServlet.service(tomcat5-servlet-2.4-
api-5.5.17.jar.so)
at javax.servlet.http.HttpServlet.service(tomcat5-servlet-2.4-
api-5.5.17.jar.so)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(catalina-5.5.17.jar.so)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(catalina-5.5.17.jar.so)
at
org.apache.catalina.core.StandardWrapperValve.invoke(catalina-5.5.17.jar.so)
at
org.apache.catalina.core.StandardContextValve.invoke(catalina-5.5.17.jar.so)
at
org.apache.catalina.core.StandardHostValve.invoke(catalina-5.5.17.jar.so)
at
org.apache.catalina.valves.ErrorReportValve.invoke(catalina-5.5.17.jar.so)
at
org.apache.catalina.core.StandardEngineValve.invoke(catalina-5.5.17.jar.so)
at
org.apache.catalina.connector.CoyoteAdapter.service(catalina-5.5.17.jar.so)
at org.apache.coyote.http11.Http11Processor.process(tomcat-
http-5.5.17.jar.so)
at org.apache.coyote.http11.Http11BaseProtocol
$Http11ConnectionHandler.processConnection(tomcat-http-5.5.17.jar.so)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(tomcat-
util-5.5.17.jar.so)
at
org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(tomcat-
util-5.5.17.jar.so)
at org.apache.tomcat.util.threads.ThreadPool
$ControlRunnable.run(tomcat-util-5.5.17.jar.so)
at java.lang.Thread.run(libgcj.so.7rh)
Caused by: org.xml.sax.SAXParseException: The reference to entity
"cmp" must end with the ';' delimiter.
at
org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown
Source)
at org.apache.xerces.util.ErrorHandlerWrapper.fatalError(Unknown
Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown
Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown
Source)
at org.apache.xerces.impl.XMLScanner.reportFatalError(Unknown
Source)
at
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanEntityReference(Unknown
Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl
$FragmentContentDispatcher.dispatch(Unknown Source)
at
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown
Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown
Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown
Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown
Source)
at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown
Source)
at org.jdom.input.SAXBuilder.build(SAXBuilder.java:453)
...21 more
Caused by:
org.xml.sax.SAXParseException: The reference to entity "cmp" must end
with the ';' delimiter.
at
org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown
Source)
at org.apache.xerces.util.ErrorHandlerWrapper.fatalError(Unknown
Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown
Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown
Source)
at org.apache.xerces.impl.XMLScanner.reportFatalError(Unknown
Source)
at
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanEntityReference(Unknown
Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl
$FragmentContentDispatcher.dispatch(Unknown Source)
at
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown
Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown
Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown
Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown
Source)
at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown
Source)
at org.jdom.input.SAXBuilder.build(SAXBuilder.java:453)
at org.jdom.input.SAXBuilder.build(SAXBuilder.java:810)
at org.jdom.input.SAXBuilder.build(SAXBuilder.java:789)
at canon.xml.servlet.XmlServlet.process(XmlServlet.java:60)
at canon.common.servlet.BaseServlet._process(BaseServlet.java:81)
at canon.common.servlet.BaseServlet.doGet(BaseServlet.java:90)
at javax.servlet.http.HttpServlet.service(tomcat5-servlet-2.4-
api-5.5.17.jar.so)
at javax.servlet.http.HttpServlet.service(tomcat5-servlet-2.4-
api-5.5.17.jar.so)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(catalina-5.5.17.jar.so)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(catalina-5.5.17.jar.so)
at
org.apache.catalina.core.StandardWrapperValve.invoke(catalina-5.5.17.jar.so)
at
org.apache.catalina.core.StandardContextValve.invoke(catalina-5.5.17.jar.so)
at
org.apache.catalina.core.StandardHostValve.invoke(catalina-5.5.17.jar.so)
at
org.apache.catalina.valves.ErrorReportValve.invoke(catalina-5.5.17.jar.so)
at
org.apache.catalina.core.StandardEngineValve.invoke(catalina-5.5.17.jar.so)
at
org.apache.catalina.connector.CoyoteAdapter.service(catalina-5.5.17.jar.so)
at org.apache.coyote.http11.Http11Processor.process(tomcat-
http-5.5.17.jar.so)
at org.apache.coyote.http11.Http11BaseProtocol
$Http11ConnectionHandler.processConnection(tomcat-http-5.5.17.jar.so)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(tomcat-
util-5.5.17.jar.so)
at
org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(tomcat-
util-5.5.17.jar.so)
at org.apache.tomcat.util.threads.ThreadPool
$ControlRunnable.run(tomcat-util-5.5.17.jar.so)
at java.lang.Thread.run(libgcj.so.7rh)
On Jun 27, 11:24 pm, "printdude1...@gmail.com"
<printdude1...@gmail.com> wrote:
On Jun 27, 7:58 am, weetat <weetat....@gmail.com> wrote:
Hi all,
I have some problem in one of my xml file which value "&" in it.
I am using JDOM API to extract xml data to database below is code:
the error line is in SAXBuilder builder = new SAXBuilder(); code.
Any one have any suggestion or ideas how to solve it ?
Thanks
protected int process(HttpServletRequest request,
HttpServletResponse response) {
int dispatchState = 0;
try {
// Build the document with SAX and Xerces, no validation
SAXBuilder builder = new SAXBuilder();
File file = new File(xmlDir);
File [] files = file.listFiles();
// list of files in directory
Map <String,ModelBean>model_map = new
HashMap<String,ModelBean>();
Map <String,String>orig_series_map = new
HashMap<String,String>();
Map <String,String>orig_category_map = new
HashMap<String,String>();
XmlAction xmlAction = ActionManager.getXmlAction();
for(int i=0;i<files.length;i++){
String filename = files[i].getAbsolutePath();
logger.log(this.getClass().getName(), "XmlServlet
process() filename" ,filename);
// Create the document
Document doc = builder.build(new File(filename));
Element root_element = doc.getRootElement();
// Get a List of all direct children as Element
objects
// content data
List allroot_attributes =
root_element.getAttributes();
Attribute attribute = root_element.getAttribute("id");
String content_id = attribute.getValue();
attribute = root_element.getAttribute("revision");
int revision = attribute.getIntValue();
attribute = root_element.getAttribute("lang");
String lang = attribute.getValue();
attribute = root_element.getAttribute("type");
String type = attribute.getValue();
attribute = root_element.getAttribute("ts-type");
String ts_type = attribute.getValue();
String xmlfile = files[i].getName();
logger.log(this.getClass().getName(), "XmlServlet
process() ts_type" ,ts_type);
logger.log(this.getClass().getName(), "XmlServlet
process() xmlfile" ,xmlfile);
String title = "";
if(ts_type.equalsIgnoreCase("Type-A"))
title = root_element.getChild("main-
text").getChild("content-title").getText();
if(ts_type.equalsIgnoreCase("Type-B"))
title = root_element.getChild("main-
text").getChild("content-title").getText();
if(ts_type.equalsIgnoreCase("Type-C"))
title = root_element.getChild("main-
text").getChild("content-title").getText();
if(ts_type.equalsIgnoreCase("Type-D"))
title = root_element.getChild("download-
page").getChild("content-title").getText();
logger.log(this.getClass().getName(), "XmlServlet
process() title" ,title);
boolean in_queue =
xmlAction.getContentInQueue(content_id,revision,lang);
logger.log(this.getClass().getName(), "XmlServlet
process() in_queue" ,String.valueOf(in_queue));
if(!in_queue){
logger.log(this.getClass().getName(), "XmlServlet
process() content_id" ,content_id);
logger.log(this.getClass().getName(), "XmlServlet
process() revision" , String.valueOf(revision));
logger.log(this.getClass().getName(), "XmlServlet
process() lang" , lang);
// add new content
xmlAction.addNewContent(content_id,revision,lang,ts_type,xmlfile,title);
// add new content reference
xmlAction.addNewContentReference(content_id,revision,lang,"");
// get all root child elements
List allChildren = root_element.getChildren();
// list all child elements
for (Iterator iter = allChildren.iterator();
iter.hasNext(); ){
Element element = (Element)iter.next();
// get product-information child elements
if(element.getName().equalsIgnoreCase("product-
information")){
List allProductInfo_Children =
element.getChildren();
for (Iterator product_info_iter =
allProductInfo_Children.iterator(); product_info_iter.hasNext(); ){
Element product_info_element =
(Element)product_info_iter.next();
// get model-information child
elements
if(product_info_element.getName().equalsIgnoreCase("model-
information")){
List allmodel_info_Children =
product_info_element.getChildren();
for (Iterator model_info_iter =
allmodel_info_Children.iterator(); model_info_iter.hasNext(); ){
Element model_info_element =
(Element)model_info_iter.next();
// get category child elements
if(model_info_element.getName().equalsIgnoreCase("category")){
String category_code=
model_info_element.getChild("category-code").getText();
String category_name=
model_info_element.getChild("category-name").getText();
orig_category_map.put(category_code,category_name);
List allcategory_Children
= model_info_element.getChildren();
for (Iterator
category_iter = allcategory_Children.iterator();
category_iter.hasNext(); ){
Element
category_element = (Element)category_iter.next();
if(category_element.getName().equalsIgnoreCase("series")){
String series_code
= category_element.getChild("series-code").getText();
String series_name
= category_element.getChild("series-name").getText();
orig_series_map.put(series_code,series_name);
List model_list =
category_element.getChildren("model");
for(Iterator
model_iter = model_list.iterator(); model_iter.hasNext(); ){
Element
model_element = (Element)model_iter.next();
ModelBean
modelBean = new ModelBean();
String
model_code = model_element.getChild("model-code").getText();
String
model_name = model_element.getChild("model-name").getText();
modelBean.setCategory_code(category_code);
modelBean.setCategory_name(category_name);
modelBean.setSeries_code(series_code);
modelBean.setSeries_name(series_name);
modelBean.setModel_name(model_name);
model_map.put(model_code,modelBean);
// add new
content models
xmlAction.addNewContentModels(content_id,revision,lang,model_code);
}
}
}
}
}
}
}
}
}
// move xml files to staging folder
files[i].renameTo(new File(stagingDir + "/" +
files[i].getName()));
}else{
// delete xml file if content still in queue
files[i].delete();
}
if(!in_queue){
Set model_set = model_map.entrySet();
for (Iterator model_map_iter =
model_set.iterator(); model_map_iter.hasNext(); ) {
Map.Entry entry =
(Map.Entry)model_map_iter.next();
String model_code = (String)entry.getKey();
ModelBean modelBean =
(ModelBean)entry.getValue();
String model_name =modelBean.getModel_name();
String series_code
=modelBean.getSeries_code();
String series_name
=modelBean.getSeries_name();
String category_code
=modelBean.getCategory_code();
String category_name
=modelBean.getCategory_name();
// add new model
xmlAction.addNewModel(model_code,model_name,category_code,series_code);
xmlAction.addNewModelOwner(model_code,category_code,series_code);
}
Set orig_series_set = orig_series_map.entrySet();
for (Iterator orig_series_iter =
orig_series_set.iterator(); orig_series_iter.hasNext(); ) {
Map.Entry entry =
(Map.Entry)orig_series_iter.next();
String series_code = (String)entry.getKey();
String series_name = (String)entry.getValue();
// add new orig series
if(!
StringCommon.check_string_empty(series_code))
xmlAction.addNewOrigSeries(series_code,series_name);
}
Set orig_category_set =
orig_category_map.entrySet();
for (Iterator orig_category_iter =
orig_category_set.iterator(); orig_category_iter.hasNext(); ) {
Map.Entry entry =
(Map.Entry)orig_category_iter.next();
String category_code = (String)entry.getKey();
String category_name =
(String)entry.getValue();
// add new orig category
if(!
StringCommon.check_string_empty(category_code))
xmlAction.addNewOrigCategories(category_code,category_name);
}
logger.log(this.getClass().getName(), "XmlServlet
process()" , "upload xml data to database ok");
}
}
} catch (Exception ex) {
logger.log(this.getClass().getName(), "XmlServlet
process()" , ex.getMessage(),ex);
}
return dispatchState;
}
I'll say it before someone else does... copy and paste the exact error
message, otherwise we have no idea what your code is doing except that
"...the error line is in SAXBuilder builder = new SAXBuilder()"