Parsing XML in JServer
I appologize for my XML ignorance up front. We've got an application with which we store a bunch of different file types in Oracle BLOBS. Some of these files are XML documents which are primarily used by an external application. There is a component to our app where we need to parse these documents and do some lightweight processing. I've done the following so far:
1. Loaded xmlparserv2.jar into the database using loadjava.
2. Written a java stored procedure that reads an XML document from a BLOB and attempts to parse it.
The problem is the DOCTYPE element in the XML document. It typically looks like this:
<!DOCTYPE Screen SYSTEM "c:\loc\screen.dtd" >
This DTD location makes sense only to the external application which uses this XML document (outside the scope of our database). I can't use a DTD in this location. Currently, I massage the xml doc as I read it out of the database so that it points to a DTD I can actually access. I hate this solution. Is there a way to tell Oracle's parser to ignore the DTD component in the xml document, or to use a different one?
Thanks in advance,
Tom
I was totally ignorant on this one. For those just as ignorant, here is the answer:
Before parsing the XML document; parse the DTD document (the one in your known location) beforehand:
parser.parseDTD(dtd_location, nodename);
dtd = parser.getDoctype();
parser.setDoctype(dtd);
parser.setValidationMode(true);
parser.parse(xml_location);
BTW, I recommend the new offering from Oracle Press: ORACLE XML Handbook.
tb
Similar Messages
-
Script for parsing xml data and inserting in DB
Thank you for reading.
I have the following example XML in an XML file. I need to write a script that can insert this data into an Oracle table. The table does not have primary keys. The data just needs to be inserted.
I do not have xsd file in this scenario. Please suggest how to modify Method 1 https://community.oracle.com/thread/1115266?tstart=0 mentioned so that I can call the XML mentioned below and insert into a table
Method 1
Create or replace procedure parse_xml is
l_bfile BFILE;
l_clob CLOB;
l_parser dbms_xmlparser.Parser;
l_doc dbms_xmldom.DOMDocument;
l_nl dbms_xmldom.DOMNodeList;
l_n dbms_xmldom.DOMNode;
l_file dbms_xmldom.DOMNodeList;
l_filen dbms_xmldom.DOMNode;
lv_value VARCHAR2(1000);
l_ch dbms_xmldom.DOMNode;
l_partname varchar2(100);
l_filename varchar2(1000);
l_temp VARCHAR2(1000);
TYPE tab_type IS TABLE OF tab_software_parts%ROWTYPE;
t_tab tab_type := tab_type();
BEGIN
l_bfile := BFileName('DIR1', 'SoftwareParts.xml');
dbms_lob.createtemporary(l_clob, cache=>FALSE);
dbms_lob.open(l_bfile, dbms_lob.lob_readonly);
dbms_lob.loadFromFile(dest_lob => l_clob, src_lob => l_bfile, amount => dbms_lob.getLength(l_bfile));
dbms_lob.close(l_bfile);
dbms_session.set_nls('NLS_DATE_FORMAT','''DD-MON-YYYY''');
l_parser := dbms_xmlparser.newParser;
dbms_xmlparser.parseClob(l_parser, l_clob);
l_doc := dbms_xmlparser.getDocument(l_parser);
dbms_lob.freetemporary(l_clob);
dbms_xmlparser.freeParser(l_parser);
l_nl := dbms_xslprocessor.selectNodes(dbms_xmldom.makeNode(l_doc),'/PartDetails/Part');
FOR cur_emp IN 0 .. dbms_xmldom.getLength(l_nl) - 1 LOOP
l_n := dbms_xmldom.item(l_nl, cur_emp);
t_tab.extend;
dbms_xslprocessor.valueOf(l_n,'Name/text()',l_partname);
t_tab(t_tab.last).partname := l_partname;
l_file := dbms_xslprocessor.selectNodes(l_n,'Files/FileName');
FOR cur_ch IN 0 .. dbms_xmldom.getLength(l_file) - 1 LOOP
l_ch := dbms_xmldom.item(l_file, cur_ch);
lv_value := dbms_xmldom.getnodevalue(dbms_xmldom.getfirstchild(l_ch));
if t_tab(t_tab.last).partname is null then t_tab(t_tab.last).partname := l_partname; end if;
t_tab(t_tab.last).filename := lv_value;
t_tab.extend;
END LOOP;
END LOOP;
t_tab.delete(t_tab.last);
FOR cur_emp IN t_tab.first .. t_tab.last LOOP
if t_tab(cur_emp).partname is not null and t_tab(cur_emp).filename is not null then
INSERT INTO tab_software_parts
VALUES
(t_tab(cur_emp).partname, t_tab(cur_emp).filename);
end if;
END LOOP;
COMMIT;
dbms_xmldom.freeDocument(l_doc);
EXCEPTION
WHEN OTHERS THEN
dbms_lob.freetemporary(l_clob);
dbms_xmlparser.freeParser(l_parser);
dbms_xmldom.freeDocument(l_doc);
END;
<TWObject className="TWObject">
<array size="240">
<item>
<variable type="QuestionDetail">
<questionId type="String"><![CDATA[30]]></questionId>
<questionType type="questionType"><![CDATA[COUNTRY]]></questionType>
<country type="String"><![CDATA[GB]]></country>
<questionText type="String"><![CDATA[Please indicate]]></questionText>
<optionType type="String"><![CDATA[RadioButton]]></optionType>
<answerOptions type="String[]">
<item><![CDATA[Yes]]></item>
<item><![CDATA[No]]></item>
</answerOptions>
<ruleId type="String"><![CDATA[CRP_GB001]]></ruleId>
<parentQuestionId type="String"></parentQuestionId>
<parentQuestionResp type="String"></parentQuestionResp>
</variable>
</item>
<item>
<variable type="QuestionDetail">
<questionId type="String"><![CDATA[40]]></questionId>
<questionType type="questionType"><![CDATA[COUNTRY]]></questionType>
<country type="String"><![CDATA[DE]]></country>
<questionText type="String"><![CDATA[Please indicate]]></questionText>
<optionType type="String"><![CDATA[RadioButton]]></optionType>
<answerOptions type="String[]">
<item><![CDATA[Yes]]></item>
<item><![CDATA[No]]></item>
</answerOptions>
<ruleId type="String"><![CDATA[CRP_Q0001]]></ruleId>
<parentQuestionId type="String"></parentQuestionId>
<parentQuestionResp type="String"></parentQuestionResp>
</variable>
</item>
</array>
</TWObject>Reposted as
Script to parse XML data into Oracle DB -
LO Error 26005 Failed to parse XML
Good Afternoon,
I currently have an Xcelsius document that is attached to a Crystal Report that is in Infoview. I have it connected by using Live Office. The Crystal report basically contains a cross tab of data and is run nightly in our system. I bring back the data into Excel in order to build an Xcelsius document off of it. I havent' been using the Live Office piece all that much until recently therefore please excuse my ignorance. I setup my data connection as a Live Office connection. My server connection seems to be correct:
http://WHGCRYSTAL3:8080/dswsbobje/services/session
However, when I try to refresh the document, I get the following error:
soapenv:Server.generalException: Failed to parse XML. (LO 26005)
Any ideas as to what this could be? I have Crystal Xcelsius Enterprise 2008. The version is 5.0.0.99 and the build number is 12,0,0,121. I think I am all updated on service packs but I could be wrong. Any help is appreciated.I downloaded all of the service packs and fixes and now I am up to date. I am still getting the error with an additional error. This is what is says:
Failed to parse XML. (LO 26005) (LO 26000)
Any other ideas as to why this is happening? -
Need help on parsing xml file...
Hi all,
I need to collect some data from an Xml file using java. I have the following code with me but I am unable to get the required result. I am unable to get the data from the tags belonging to the header and footer elements. Please find the code and the sample xml file below.
Program to parse XML:
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
public class JobLogDetails3{
//No generics
List myJobs;
Document dom;
public JobLogDetails3(){
//create a list to hold the job objects
myJobs = new ArrayList();
public void runJobDetails() {
//parse the xml file and get the dom object
parseXmlFile();
//get each joblog element and create a job object
parseDocument();
//Iterate through the list and print the data
printData();
private void parseXmlFile(){
//get the factory
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
try {
//Using factory get an instance of document builder
DocumentBuilder db = dbf.newDocumentBuilder();
//parse using builder to get DOM representation of the XML file
dom = db.parse("test.xml");
}catch(ParserConfigurationException pce) {
pce.printStackTrace();
}catch(SAXException se) {
se.printStackTrace();
}catch(IOException ioe) {
ioe.printStackTrace();
private void parseDocument(){
//get the root elememt
Element docEle = dom.getDocumentElement();
//get a nodelist of <joblog> elements
NodeList nl = dom.getElementsByTagName("*");
if(nl != null && nl.getLength() > 0) {
for(int i = 0 ; i < nl.getLength();i++) {
//get the joblog element
Element el = (Element)nl.item(i);
//get the joblog object
Job J = getJob(el);
//add it to list
myJobs.add(J);
* I take an joblog element and read the values in, create
* an joblog object and return it
* @param JobEl
* @return
private Job getJob(Element JobEl) {
//for each <joblog> element get text or int values of
//name ,id, age and name
String jobServer = getTextValue(JobEl,"server");
String jobName = getTextValue(JobEl,"name");
String jobClient = getTextValue(JobEl,"machine_name");
String jobStart = getTextValue(JobEl,"start_time");
String jobType = getTextValue(JobEl,"type");
String jobEnd = getTextValue(JobEl,"end_time");
String jobSize = getTextValue(JobEl,"new_processed_bytes");
//Create a new Job with the value read from the xml nodes
Job J = new Job(jobServer,jobName,jobClient,jobStart,jobType,jobEnd,jobSize);
return J;
* I take a xml element and the tag name, look for the tag and get
* the text content
* i.e for <employee><name>John</name></employee> xml snippet if
* the Element points to employee node and tagName is name I will return John
* @param ele
* @param tagName
* @return
private String getTextValue(Element ele, String tagName) {
String textVal = null;
NodeList nl = ele.getElementsByTagName(tagName);
if(nl != null && nl.getLength() > 0) {
Element el = (Element)nl.item(0);
textVal = el.getFirstChild().getNodeValue();
return textVal;
* Calls getTextValue and returns a int value
* @param ele
* @param tagName
* @return
private int getIntValue(Element ele, String tagName) {
//in production application you would catch the exception
return Integer.parseInt(getTextValue(ele,tagName));
* Iterate through the list and print the
* content to console
private void printData(){
System.out.println("No of Jobs '" + myJobs.size() + "'.");
Iterator it = myJobs.iterator();
while(it.hasNext()) {
System.out.println(it.next().toString());
public static void main(String[] args){
//create an instance
JobLogDetails JLD = new JobLogDetails();
//call run example
JLD.runJobDetails();
Job Class
public class Job {
private String jobServer;
private String jobName;
private String jobClient;
private String jobStart;
private String jobType;
private String jobEnd;
private String jobSize;
public Job(){
public Job(String jobServer,String jobName,String jobClient,String jobStart,String jobType,String jobEnd,String jobSize ) {
this.jobServer = jobServer;
this.jobName = jobName;
this.jobClient = jobClient;
this.jobStart = jobStart;
this.jobType = jobType;
this.jobEnd = jobEnd;
this.jobSize = jobSize;
public String getjobServer() {
return jobServer;
public void setjobServer(String jobServer) {
this.jobServer = jobServer;
public String getjobName() {
return jobName;
public void setjobname(String jobName) {
this.jobName = jobName;
public String getjobClient() {
return jobClient;
public void setjobClient(String jobClient) {
this.jobClient = jobClient;
public String getjobStart() {
return jobStart;
public void setjobStart(String jobStart) {
this.jobStart = jobStart;
public String getjobType() {
return jobType;
public void setjobType(String jobType) {
this.jobType = jobType;
public String getjobEnd() {
return jobEnd;
public void setjobEnd(String jobEnd) {
this.jobEnd = jobEnd;
public String getjobSize() {
return jobSize;
public void setjobSize(String jobSize) {
this.jobSize = jobSize;
public String toString() {
StringBuffer sb = new StringBuffer();
sb.append(getjobServer());
sb.append(",");
sb.append(getjobName());
sb.append(",");
sb.append(getjobClient());
sb.append(",");
sb.append(getjobType());
sb.append(",");
sb.append(getjobStart());
sb.append(",");
sb.append(getjobEnd());
sb.append(",");
sb.append(getjobSize());
sb.append(",");
return sb.toString();
Sample XML File:
<?xml version="1.0" encoding="UTF-16" ?>
- <joblog>
<job_log_version version="2.0" />
- <header>
<filler>======================================================================</filler>
<server>Job server: TGBBAK</server>
<name>Job name: TGBSAP4-SQL-SQL DB Servers S2T - High-Weekly Full Backup</name>
<start_time>Job started: 26 September 2011 at 01:00:04</start_time>
<type>Job type: Backup</type>
<log_name>Job Log: GFD_TGBBAK_71887.xml</log_name>
<filler>======================================================================</filler>
</header>
<media_mount_date>Drive and media mount requested: 26/09/2011 01:00:04</media_mount_date>
- <media_drive_and_media_info>
<media_mount_date>Drive and media information from media mount: 26/09/2011 01:00:39</media_mount_date>
<robotic_library_name>Robotic Library Name: HP 1</robotic_library_name>
<drive_name>Drive Name: LTO4_2</drive_name>
<slot>Slot: 43</slot>
<media_label>Media Label: 000059L</media_label>
<media_guid>Media GUID: {a6ca0062-7a6f-4b4b-8144-732ca25f2f9d}</media_guid>
<media_overwrite_date>Overwrite Protected Until: 25/10/2011 19:24:58</media_overwrite_date>
<media_append_date>Appendable Until: 02/10/2011 14:00:30</media_append_date>
<media_set_target>Targeted Media Set Name: Weekly Tape</media_set_target>
</media_drive_and_media_info>
- <backup>
<filler>======================================================================</filler>
<title>Job Operation - Backup</title>
<append_or_overwrite>Media operation - append.</append_or_overwrite>
<compression>Compression Type: Hardware [if available, otherwise none]</compression>
<verify_option>WARNING: The option 'Verify after backup completes' was not selected. Performing a verify operation to make sure that media can be read after the backup has completed is recommended.</verify_option>
<filler>======================================================================</filler>
- <machine>
<machine_name>TGBSAP4.Tetley.Grp</machine_name>
<info>Network control connection is established between 10.22.2.18:3271 <--> 10.22.2.4:10000</info>
<info>Network data connection is established between 10.22.2.18:3301 <--> 10.22.2.4:3094</info>
- <set>
<set_resource_name>TGBSAP4.Tetley.Grp</set_resource_name>
<tape_name>Family Name: "Media created 25/09/2011 13:59:55"</tape_name>
- <volume>
<display_volume>Backup of "TGBSAP4.Tetley.Grp "</display_volume>
</volume>
<description>Backup set #45 on storage media #1 Backup set description: "Weekly Full Backup"</description>
<backup_type>Backup Method: Full - Back up entire database or filegroup</backup_type>
<agent_started>Microsoft SQL Server Agent: Started</agent_started>
<start_time>Backup started on 26/09/2011 at 01:01:45.</start_time>
- <database>
<database>Database PRD</database>
</database>
- <database>
<database>Database master</database>
</database>
- <database>
<database>Database model</database>
</database>
- <database>
<database>Database msdb</database>
</database>
<end_time>Backup completed on 26/09/2011 at 02:42:25.</end_time>
- <summary>
<backed_up_database>Backed up 4 databases</backed_up_database>
<new_processed_bytes>Processed 573363576542 bytes in 1 hour, 40 minutes, and 40 seconds.</new_processed_bytes>
<vlm_hist_rateformat2>Throughput rate: 5432 MB/min</vlm_hist_rateformat2>
</summary>
<filler>----------------------------------------------------------------------</filler>
</set>
</machine>
</backup>
- <footer>
<filler>======================================================================</filler>
<end_time>Job ended: 26 September 2011 at 02:43:12</end_time>
<engine_completion_status>Job completion status: Successful</engine_completion_status>
<filler>======================================================================</filler>
<completeStatus>19</completeStatus>
</footer>
</joblog>1. your code does not compile (in your main method you try to create an instance of a class which does not exist).
2. your XML document is not well formed.
+[Fatal Error] test.xml:34:74: The content of elements must consist of well-formed character data or markup.+
org.xml.sax.SAXParseException: The content of elements must consist of well-formed character data or markup.
Maybe there are other problems but you can start by fixing these. -
Parse XML in a java stored proc
I am trying to parse an xml document in a java stored procedure. Just following my nose, I have developed a stored proc that works fine in development (outside the database using JRE 1.4.1) using the Xerces 2.5 parser. But, after having transferred the xerces xercesImpl.jar, xmlapis.jar, and my implementation class into oracle using loadjava when I call my stored proc the code throws an exception trying to build the document with an error like:
NoClassDef exception org.apache.xerces.jaxp.DocumentFactoryBuilderImpl
My Code looks like this:
import java.io.IOException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.FactoryConfigurationError;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;
InputStream is = getXMLAsInputStream(xml);
try {
DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse( is );
... parse the document ....
catch (FactoryConfigurationError e) {
// unable to get a document builder factory
The exception caught is a FactoryConfigurtionError.
I'm not particularly attached to xerces, I'm really just looking for a way to parse XML inside my java stored proc, so any help to solve my problem, or an alternative suggestion will be greatly appreciated.
thanks
DaleI looked again and sure enough the xerces implementation classes were missing. I had run a .cmd file containing these two lines, but it looks like only the first one ran...
loadjava -u ncc/xyz@usd -v -r M:\Database\JavaGeocode\Xerces2_5_0\xml-apis.jar
loadjava -u ncc/xyz@usd -v -r M:\Database\JavaGeocode\Xerces2_5_0\xercesImpl.jar
Now I've got everything working fine with Xerces!
Dale -
Hi ,
Good Morning to all
in osb replace action am using xquery transformation resource.
source code of xquery is :
====================================================================================
(:: pragma bea:global-element-parameter parameter="$addition1" element="ns0:Addition" location="../wsdl/NewWSDLFile.wsdl" ::)
(:: pragma bea:global-element-return element="ns1:process" location="../bpelprocess1_client_ep.wsdl" ::)
declare namespace ns1 = "http://xmlns.oracle.com/POProcessing/AdditionOSB/BPELProcess1";
declare namespace ns0 = "http://www.example.org/NewWSDLFile/";
declare namespace xf = "http://tempuri.org/ServiceCallout/trans/route/";
declare function xf:route($addition1 as element(ns0:Addition))
as element(ns1:process) {
<ns1:process>
<ns1:value1>{ data($addition1/value1) }</ns1:value1>
<ns1:value2>{ data($addition1/value2) }</ns1:value2>
</ns1:process>
declare variable $addition1 as element(ns0:Addition) external;
xf:route($addition1)
=====================================================
at the time of running "error is Error parsing XML: {err}FORG0005: expected exactly one item, got 0 items " in replace action.
how to resolve this problem...
Thanks & Regards
venkyThe reason for the error is the xquery is not able to find the values in the input... Check the input and namespaces...
Try...
<ns1:value1>{ data($addition1/ns0:value1) }</ns1:value1>
<ns1:value2>{ data($addition1/ns0:value2) }</ns1:value2>Cheers,
Vlad -
How do you store parsed XML data in an array
Hi, i am trying to complete a small program which implements the SAX parser to parse an XML file. My problem is that i am writing a custom class to store the parsed data into an array, and then make the array available to the main program via a simple method which returns the array. I know this must be very simple to do, but i seem to have developed a mental block with this part of the program. I can parse the data and print all the elements to the screen, but i just cant figure out how to store all the data elements into the array. I will post the class which is supposed to do this, and ask anyone out there if they know what i'm doing wrong, and also, if there is a more effeicient way of achieving this ( i expect there definitely is!! but i have never used the SAX parser before and am getting confused by the API docs on it!!) Any help very much appreciated.
Here is my attempt at coding the class to handle the parsed XML data
class Sink extends org.xml.sax.helpers.DefaultHandler
implements org.xml.sax.ContentHandler{
Customer[] customers = new Customer[20];
int count = 1;
int x = 0;
int tagCount = 0;
String name;
String custID;
String username;
String address;
String phoneNum;
public void startElement(String uri, String localName, String rawName, final org.xml.sax.Attributes attributes)throws org.xml.sax.SAXException{
//count the number of <name> tags in the XML file
if(rawName.equals("name")){
tagCount++;
public void characters(char[] ch, int start, int len){
//get the current string
String text = new String(ch, start, len);
String text1 = text.trim();
//there are 5 elements for each customer found in the XML file so when the count reaches 6
// i reset this to 1
if(count == 6){
count = count - 5;
if(text1.length()>0 && count == 1){
name = text1;
System.out.println(name);
}else{
if(text1.length()>0 && count == 2){
custID = text1;
System.out.println(custID);
}else{
if(text1.length()>0 && count == 3){
username = text1;
System.out.println(username);
}else{
if(text1.length()>0 && count == 4){
address = text1;
System.out.println(address);
}else{
if(text1.length()>0 && count == 5){
phoneNum = text1;
System.out.println(phoneNum);
//add data to the customer array
customers[x] = new Customer(name, custID, username, address, phoneNum);
// increment the array index counter
x = x+1;
}//end of if
}//end else
}//end else
}//end else
}//end else
}//end of characters method
public void endDocument(){
System.out.println("There are " + tagCount +
" <name> elements.");
}//end of class Sink
Before the end of this class i also need to make the array available to the calling program!!
Any help would be much appreciated
Thanks
IainOk, yer going about this all the wrong way. You shouldn't have to maintain a count of all the elements. Basically you are locking yourself into the XML tags not only all being there but are assuming they are all in the same order. What you should do is in your characters() method, put all of the characters into a string buffer. Then, in endElement() (which you dont use btw, you should) you grab the information that is in the string buffer and store it into your Customer object depending on what the tagName is.
Also, you should probably use a List to store all the Customer objects and not an single array, it's more dynamic and you arent locked into a set number of Customers.
I wont do it all for you, but I'll give you a good outline to use.
public class CustomerHandler extends DefaultHandler {
private java.util.List customerList; // List of Customer objects
private java.util.StringBuffer buf; // StringBuffer to store the string of characters between the start and end tags
private Customer customer; // Customer object that is initialized with each entry.
public CustomerHandler() {
customerList = new java.util.ArrayList(); // Initialize the List
buf = new java.util.StringBuffer(); // Initialize the string buffer
// Make your customer list available to other classes
public java.util.List getCustomerList() {
return customerList;
public void startElement(String nsURI, String sName, String tagName, Attributes attributes) throws SAXException {
// Clear the String Buffer
// If the tagName is "Customer" then create a new Customer object
public void characters(char[] ch, int start, int length) {
// append the characters into the string buffer
public void endElement(String nsURI, String sName, String tagName) throws SAXException {
// If the tagName is "Customer" add your customer object to the List
// Place the data from the String Buffer into a String
// Depending on the tagName, call the appropriate set method on your customer object
} -
Can't parse xml from applet using dom on linux on Netscape 7 using jre 1.4.
Hi,
I can't seem to parse xml from an applet on linux on Netscape 7 using the JRE 1.4.
My code looks like the following:
StringBufferInputStream is = new StringBufferInputStream("<foo></foo>");
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = null;
try
builder = factory.newDocumentBuilder();
domDocument = builder.parse(is); // this line creates an exception
catch (Exception e)
System.out.println(e);
This code works fine from an applet on windows. On linux, the error message is:
java.security.AccessControlException: access denied (java.util.PropertyPermission entityExpansionLimit read)
I've tried both JRE 1.4.0_04 and 1.4.1_03
Thanks!
QThere's another posting about this same problem (platform unspecified), but the same error message. I was also having this problem (Windows 1.4.03) and swithced back to 1.4.01 and the problem went away. In the future, I may sign my applets to get a more generous security policy. But, I'm sure it'll be a lot of work (vs. a line of code somewhere).
-
Can't parse xml file in jar file when can't connect to web server
My JNLP application throw ConnectException when trying to parse xml during web server offline.
Steps,
1. JNLP application has been launched once and all related jar and xml files are already downloaded to local cache.
2. Then I close web server to test offline launch.I launch the JNLP application using shortcut with -offline parameter.
3. However the JRE internal xml parser tries to connect to web server and report connection error as web server is down now.
My concern is the file is already in the cache, why java still try to connect URL. This error happens in JRE 1.5, but it doesn't happen in JRE 1.6. It only happens when web server is down in JRE 1.5.
I think it may be a bug of JRE, do any one can give me some hint about how to resolve?
Thanks in advance!!
I also moved the code piece to a simple web start example, following it the error and code pieces.
Error Trace in Java console,
ava.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at sun.net.NetworkClient.doConnect(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.<init>(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at sun.net.www.protocol.jar.URLJarFile.retrieve(Unknown Source)
at sun.net.www.protocol.jar.URLJarFile.getJarFile(Unknown Source)
at sun.net.www.protocol.jar.JarFileFactory.get(Unknown Source)
at sun.net.www.protocol.jar.JarURLConnection.connect(Unknown Source)
at sun.net.www.protocol.jar.JarURLConnection.getInputStream(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.startEntity(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.startDTDEntity(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDTDScannerImpl.setInputSource(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$DTDDispatcher.dispatch(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(Unknown Source)
at javax.xml.parsers.DocumentBuilder.parse(Unknown Source)
at EntXmlUtil.buildDocument(EntXmlUtil.java:57)
at Notepad.testParseXML(Notepad.java:870)
at Notepad.main(Notepad.java:153)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.sun.javaws.Launcher.executeApplication(Unknown Source)
at com.sun.javaws.Launcher.executeMainClass(Unknown Source)
at com.sun.javaws.Launcher.continueLaunch(Unknown Source)
at com.sun.javaws.Launcher.handleApplicationDesc(Unknown Source)
at com.sun.javaws.Launcher.handleLaunchFile(Unknown Source)
at com.sun.javaws.Launcher.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Notepad.java
public void testParseXML() {
URL xmlURL=Notepad.class.getClassLoader().getResource("xml/Login.xml");
try {
org.w3c.dom.Document doc = EntXmlUtil.buildDocument(xmlURL);
System.out.println("Test"+doc);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
EntXMLUtil.java
private static DocumentBuilderFactory dbf = null;
static {
dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
dbf.setValidating(true);
dbf.setIgnoringComments(true);
dbf.setIgnoringElementContentWhitespace(true);
public static DocumentBuilderFactory getDocBuilderFactory() {
return EntXmlUtil.dbf;
public static Document buildDocument(URL url, String systemId) throws Exception {
DocumentBuilder db;
Document doc;
InputStream is;
String sysId = null;
if(systemId == null)
sysId = url.toExternalForm();
else
sysId = systemId;
db = EntXmlUtil.getDocBuilderFactory().newDocumentBuilder();
is = url.openStream();
doc = db.parse(is, sysId);
is.close();
return doc;
}I finally got a temperary work around for this issue, using JRE5 version lower than update 16(not include update 16).
i found Sun modify the URL which returned by XXX.class.getClassLoader().getResource("xml/Test.xml,") after update 15, previous it is related with the cache path, like C:\Users\epenwei\AppData\LocalLow\Sun\Java\Deployment\cache\javaws\http\Dlocalhost\P80\DMEntriView\DMapp\AMNotepad.jar!/xml/Test.xml, but after it changes to network path, like http://localhost/Notepad/app/notepad.jar!/xml/Test.xml. However, the latter address doesn't work in Sun's own class com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity if offline.It tried to create new URL then connect to web server. So exception is thrown since web server is down.
if (reader == null) {
stream = xmlInputSource.getByteStream();
if(stream != null && encoding != null)
declaredEncoding = true;
if (stream == null) {
URL location = new URL(expandedSystemId);
URLConnection connect = location.openConnection();
if (connect instanceof HttpURLConnection) {
setHttpProperties(connect,xmlInputSource);
I am not sure whether it is a Java new bug since I only read the codes and didn't debug Sun code. But I am very curious that I have already specify <j2se version="1.5.0_12" href="http://java.sun.com/products/autodl/j2se" /> to specify update 12 for my jws application. And I also see the Java console display like following
Java Web Start 1.5.0_18
Using JRE version 1.5.0_12 Java HotSpot(TM) Client VM
Why java still uses my latest jre lib to run my application?
Edited by: wei000 on May 22, 2009 5:32 AM -
Xerces - Parse XML from String
I am trying to parse an xml string using Xerces.
I have the following code:
String xml = <segments meters="8643" seconds="538" distance="5.4 mi" time="8 mins"><segment id="seg0" pointIndex="0" meters="122" seconds="11" distance="0.1 mi" time="11 secs">Head <b>southwest</b> from <b>B Ave NE</b>
</segment>
<segment id="seg1" pointIndex="2" meters="239" seconds="22" distance="0.1 mi" time="21 secs">Turn <b>left</b> at <b>19th St NE</b></segment>
<segment id="seg2" pointIndex="5" meters="2985" seconds="192" distance="1.9 mi" time="3 mins">Turn <b>right</b> at <b>1st Ave NE</b></segment>
<segment id="seg3" pointIndex="43" meters="3280" seconds="211" distance="2.0 mi" time="3 mins">Continue on <b>1st Ave SW/1st Ave NW</b></segment>
<segment id="seg4" pointIndex="96" meters="158" seconds="10" distance="0.1 mi" time="10 secs">Bear <b>right</b> at <b>US-151-BR S</b></segment>
<segment id="seg5" pointIndex="102" meters="1859" seconds="93" distance="1.2 mi" time="1 min">Turn <b>right</b> at <b>16th Ave SW</b></segment>;
XMLReader reader = new SAXParser();
reader.setContentHandler(new Handler());
reader.parse(xml);I am getting the followoing error:
org.xml.sax.SAXParseException: File "<segments meters="8643" seconds="538" distance="5.4 mi" time="8 mins"><segment id="seg0" pointIndex="0" meters="122" seconds="11" distance="0.1 mi" time="11 secs">Head <b>southwest</b> from <b>B Ave NE</b></segment><segment id="seg1" pointIndex="2" meters="239" seconds="22" distance="0.1 mi" time="21 secs">Turn <b>left</b> at <b>19th St NE</b></segment><segment id="seg2" pointIndex="5" meters="2985" seconds="192" distance="1.9 mi" time="3 mins">Turn <b>right</b> at <b>1st Ave NE</b></segment><segment id="seg3" pointIndex="43" meters="3280" seconds="211" distance="2.0 mi" time="3 mins">Continue on <b>1st Ave SW/1st Ave NW</b></segment><segment id="seg4" pointIndex="96" meters="158" seconds="10" distance="0.1 mi" time="10 secs">Bear <b>right</b> at <b>US-151-BR S</b></segment><segment id="seg5" pointIndex="102" meters="1859" seconds="93" distance="1.2 mi" time="1 min">Turn <b>right</b> at <b>16th Ave SW</b></segment></segments>" not found.
at org.apache.xerces.framework.XMLParser.reportError(XMLParser.java:1219)
at org.apache.xerces.readers.DefaultEntityHandler.startReadingFromDocument(DefaultEntityHandler.java:501)
at org.apache.xerces.framework.XMLParser.parseSomeSetup(XMLParser.java:314)
at org.apache.xerces.framework.XMLParser.parse(XMLParser.java:1097)
at org.apache.xerces.framework.XMLParser.parse(XMLParser.java:1139)
at com.shiftyeyes.xmlTest.main(xmlTest.java:34)
Exception in thread "main" anyone know how I can fix this? Thanks!!reader.parse(new InputSource(new StringReader(xml)));
-
Java stored proc performance parsing XML docs
Hi
We are using ORACLE 8i(8.1.6). I have a JAVA Stored procedure that parses XML doc and returns tha values. If I am testing on the box, I get an avg. return time of 2 secs. If I have 20 users, my return time for all went to 25 to 35 secs?
Are there any parameters on ORACLE I can modify to increase the performance. We are developing app for 1000 to 1500 users. I dont want to guess the time based on my test with 20 users.
Any help will be greatly appreciated.
Thank You
RajuRaju,
Oracle 8.1.7 should be better choice for you since it does have the XML stuff
natively compiled.
Regarding scaleability the JVM should scale
very well. However let us know what you find.
- Stefan -
Parsing XML from a session bean
Hi,
I am trying to use a Sax parser for parsing xml received from a back end
legacy system. The code is executed from a Session bean.
Debugging learned me that the parse() method on the parser hangs the
container without any error or exception trace. The code works fine outside
a container.
All help will be highly appreciated.
KurtI found out that the InputStream implementation used parsing source inside
the container is different
then from the one outside (other type of VM of course!). The Weblogic
implementation blocks at the end of
the stream, while the normal SUN JDK 1.3 returns. This is not a bug, the bug
I found is in my proxy that allows
the connection to the backend. This proxy allows HTTP connections, and I
parse the XML received over HTTP.
Regards,
Kurt
"Todd Karakashian" <[email protected]> wrote in message
news:[email protected]..
That's seems odd. Perhaps there is something going on in your document
handler code that triggers a hang in the environment of the server.
When you see the hang, instruct the VM to give you a thread dump (type
control-<break> on Windows, <control>-\ (backslash) on UNIX in the
window in which the server is running; the results are dumped to
stderr). That will show what every thread in the server is doing. If you
email or post the thread dump, I will take a look at it and see if I can
see what is going on. Also, let us know which platform, VM, parser, and
WebLogic version you are using.
Regards,
-Todd
Kurt Quirijnen wrote:
Hi,
I am trying to use a Sax parser for parsing xml received from a back end
legacy system. The code is executed from a Session bean.
Debugging learned me that the parse() method on the parser hangs the
container without any error or exception trace. The code works fine
outside
a container.
All help will be highly appreciated.
Kurt--
Todd Karakashian
BEA Systems, Inc.
[email protected] -
Parse XML input stream (no .xml file)?
i have a java applet calling a web service that returns XML data as an input stream (char by char from SOAP) to this applet. if i append a all the chars to a string, is there some XML tool that will parse the string as if it were an XML document (like a getElement functions)?
the applet cannot write the data to a .xml file, and i don't want to mess around with .jarsigning. any ideas?
thanks,
jonathanThe XML parsers you are likely to be using support receiving input from a variety of sources besides files. For example you could parse XML from a String variable by passing a StringReader wrapping that String to the parser. Check the documentation for more details.
-
I am trying to parse XML Schema using XSOM. The Schema has <xs:include>s
e.g. I have first.xsd which includes second.xsd and second.xsd again includes third.xsd.
First.xsd
<xs:include schemaLocation="../Second.xsd">....
Second.xsd
<xs:include schemaLocation="Third.xsd">....
When I parse "First.xsd" parser passes the correct path "C:/XSDSchema/Second.xsd"(First.xsd resides in "C:/XSDSchema/Schema/") to the EntityResolver's resolveEntity method. But for Second.xsd it passes "Third.xsd" only (Third.xsd resides in "C:/XSDSchema/" ) .
Any Idea ?????Here is a screenshort of the part of my workflow:
In the mappings of the "Set Value" activity, I have one line with those properties:
Location: /process_data/bonusValidationForm/object/data/xdp/datasets/data/BonusValidationForm/buMan agerID
Expression: /process_data/currentUser/object/@userId
Where:
bonusValidationForm is a process variable of my workflow that point my xdp form
buManagerID is the textfield I want to set
currentUser is a process variable (type User) that was well setted by the task Find BU Manager -
Error in retrieving and parsing XML File
Hi Folks
I am Working on People centric user interface, While i am custimizing a application in Business application Builder i am getting this error
" Error in retrieving and parsing XML File "
can any body look on this and give me the solution
it will be rewarded
Regards
M.S.KumarHello,
As mentionned by SAP_TECH, avoid to use the BAB.
Go to CRMC_BLUEPRINT_C and use the different option in the menu to customize the field group, toolbar group, events, ...
Use the PCUI cookbook to find your way.
Regards,
Fred
Maybe you are looking for
-
Replicating Circulation workflow in Sharepoint Online
Hi, I am looking at replicating the circulation workflow in SharePoint Online, but without success. The requirement is to send a policy document to one or more employees and capture their "signature" - could be just a text field with their name print
-
Hello, I've just upgraded to the Creative Cloud but still have CS3 installed on my MacBook Pro. How do I remove CS3? I don't want to delete it completely, so is it just a case of copying to an external hard drive and then deleting from the MacBook? O
-
Can't Move songs between playlists
Is there a bug on Spotify for Iphone (latest IOS)? I can't add songs or transfer them btw playlists.
-
Webi Chart Dynamic X Axis lenght
Dear experts, Is it possible to define an X axis as dynamic? I mean, is there a way that the chart size changes accordingly to the data show, i.e, if I choose to see only January (X axis) I would have a smaller chart (1 column only) but if I choose t
-
Instantiate Oracle BPM Process Webservice from the OSB.
Hi, In our project we have one requirement i.e Instantiate Oracle BPM Process Webservice from the OSB.After register BPM service in to OSB I am creating one Message flow to instantiate BPM Process. first call to startSession Operation, then use respo