Parsing xml in 10g
Hi,
I want to parse a xml file by plsql procedure and use it by xmldom package.
It working perfectly when I use oracle 9.2.05, but I can't use file greater than 10926 bytes when I use oracle 10.1.0.3 because this error stack appear.
ORA-31011: XML parsing failed
ORA-19202: Error occurred in XML processing
LPX-00200: could not convert from encoding UTF-8 to UCS2
Error at line 630
ORA-06512: at "XDB.DBMS_XMLDOM", line 4180
ORA-06512: at "XDB.DBMS_XMLDOM", line 4205
ORA-06512: at "WIPO.TESTXML", line 191
ORA-06512: at line 1
Code on line 191 is:
nl := xmldom.getElementsByTagName(doc, '*');
When I use file less than 10926 bytes then 10g working like 9i database.
Can anybody know what's wrong?
thanks
Milan
Hi,
I want to parse a xml file by plsql procedure and use it by xmldom package.
It working perfectly when I use oracle 9.2.05, but I can't use file greater than 10926 bytes when I use oracle 10.1.0.3 because this error stack appear.
ORA-31011: XML parsing failed
ORA-19202: Error occurred in XML processing
LPX-00200: could not convert from encoding UTF-8 to UCS2
Error at line 630
ORA-06512: at "XDB.DBMS_XMLDOM", line 4180
ORA-06512: at "XDB.DBMS_XMLDOM", line 4205
ORA-06512: at "WIPO.TESTXML", line 191
ORA-06512: at line 1
Code on line 191 is:
nl := xmldom.getElementsByTagName(doc, '*');
When I use file less than 10926 bytes then 10g working like 9i database.
Can anybody know what's wrong?
thanks
Milan
Similar Messages
-
SOAPFaultException: error in msg parsing: xml was empty, didn't parse!
Using the web service example from http://www.oracle-base.com/articles/10g/utl_dbws-10g.php. Can anyone tell me why I can't call this web service twice within the same database session? The first call seems to work for each session, but the second generates an error.
SQL> select * from v$version;
BANNER
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
PL/SQL Release 11.2.0.3.0 - Production
CORE 11.2.0.3.0 Production
TNS for Linux: Version 11.2.0.3.0 - Production
NLSRTL Version 11.2.0.3.0 - Production
SQL> CREATE OR REPLACE FUNCTION add_numbers(p_int_1 IN NUMBER,
2 p_int_2 IN NUMBER) RETURN NUMBER AS
3 l_service sys.utl_dbws.service;
4 l_call sys.utl_dbws.call;
5
6 l_wsdl_url VARCHAR2(32767);
7 l_namespace VARCHAR2(32767);
8 l_service_qname sys.utl_dbws.qname;
9 l_port_qname sys.utl_dbws.qname;
10 l_operation_qname sys.utl_dbws.qname;
11
12 l_xmltype_in sys.xmltype;
13 l_xmltype_out sys.xmltype;
14 l_return NUMBER;
15 BEGIN
16 l_wsdl_url := 'http://www.oracle-base.com/webservices/server.php?wsdl';
17 l_namespace := 'http://www.oracle-base.com/webservices/';
18
19 l_service_qname := sys.utl_dbws.to_qname(l_namespace,
20 'Calculator');
21 l_port_qname := sys.utl_dbws.to_qname(l_namespace,
22 'CalculatorPort');
23 l_operation_qname := sys.utl_dbws.to_qname(l_namespace,
24 'ws_add');
25
26 l_service := sys.utl_dbws.create_service(wsdl_document_location => urifactory.geturi(l_wsdl_url),
27 service_name => l_service_qname);
28
29 l_call := sys.utl_dbws.create_call(service_handle => l_service,
30 port_name => l_port_qname,
31 operation_name => l_operation_qname);
32
33 l_xmltype_in := sys.xmltype('<?xml version="1.0" encoding="utf-8"?>
34 <ws_add xmlns="' || l_namespace || '">
35 <int1>' || p_int_1 || '</int1>
36 <int2>' || p_int_2 || '</int2>
37 </ws_add>');
38 l_xmltype_out := sys.utl_dbws.invoke(call_handle => l_call,
39 request => l_xmltype_in);
40
41 sys.utl_dbws.release_call(call_handle => l_call);
42 sys.utl_dbws.release_service(service_handle => l_service);
43
44 l_return := l_xmltype_out.extract('//return/text()').getnumberval();
45 RETURN l_return;
46 END;
47 /
Function created
SQL> BEGIN
2 dbms_output.put_line(add_numbers(1,
3 4));
4 dbms_output.put_line('first call succeeded');
5 dbms_output.put_line(add_numbers(1,
6 9));
7 dbms_output.put_line('second call succeeded');
8 END;
9 /
5
first call succeeded
BEGIN
dbms_output.put_line(add_numbers(1,
4));
dbms_output.put_line('first call succeeded');
dbms_output.put_line(add_numbers(1,
9));
dbms_output.put_line('second call succeeded');
END;
ORA-29532: Java call terminated by uncaught Java exception: javax.xml.rpc.soap.SOAPFaultException: error in msg parsing:
xml was empty, didn't parse!
ORA-06512: at "SYS.UTL_DBWS", line 404
ORA-06512: at "SYS.UTL_DBWS", line 401
ORA-06512: at "GLYODER.ADD_NUMBERS", line 38
ORA-06512: at line 6hi Gyoder
Do you resolve this problem?
Thanks -
Parsing XML using SDO API.
Hi
I am looking to see if JDeveloper comes with necesssary SDO APIs to help
a developer parse XML. I am looking at this as a replacement for JAXB.
I have access to JDev 11g and 10g.
If it is possible can you please tell me
1) What are the libraries to include?
2) Any tutorials available.
Thanks
KartikHello Kartik,
Oracle TopLink will include an SDO 2.1 implementation as part of the AS 11R1 release. You can take a look at Technical Preview 2 here:
http://www.oracle.com/technology/products/ias/toplink/preview/index.html
There isn't much in the way of SDO documentation yet, but I can provide you with some samples if you wish.
First though, you mention that you are looking for a replacement for JAXB. I have represented Oracle on both the JAXB 2.0 and SDO 2.1/3.0 specifications so if you care to provide details on what you're building, maybe I can offer an opinion. If you don't wish to post to the list, you can email me at [email protected]
Oracles JAXB and SDO implementations are both build on top of TopLink's object-to-XML mapping technology. This may also be an appropriate technology choice for you.
For more information on TopLink OXM see:
http://www.oracle.com/technology/products/ias/toplink/oxm/index.html
-Blaise -
Parse XML document ,create table according to tags & load data to table
Hi All!
I have one of the most common problem, one faces when dealing with xml stuff and oracle.I get xml documents, with each file having different tags.I want to write a pl/sql procedure such that, the xml file is parsed, a table is created with the tag names becoming the column names and all the nodes' data get inserted into the table as rows.I am using oracle 10g.
I read a thread at the following url:
Parse XML and load into table
But did not get much of it.
Can anybody please tell me how to accomplish this.
Thanking in advance.
Regards,
Deepika.Why do people have such an aversion to the XML DB forum for XML questions...
See FAQ for XML DB forum here: XML DB FAQ
Explains all about getting XML into tables in the database. -
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? -
Issue in running a 9i version Page XML in 10g JDeveloper
Hi
In our 11i to R12 upgrade project we are trying to run our custom 9i version Page XMLs in 10g JDeveloper. We imported the JPR itself in 10g Jdeveloper and it did conversion while loading. But when we tried to run the pages we are getting
java.lang.NullPointerException
at oracle.apps.fnd.framework.webui.OASlideMenuUtil.prepareNavAndFavList(Unknown Source) error.
We found out that it is because of the missing "Navigation and Favorites options" that comes along with R12 version pages. We confirmed it by creating a new page in 10g Jdev and copy pasted all the regions from the old page to the new page. It is working fine. Now the doubt i have is,
Wont 10g Jdev take care of this during the conversion of the Page XMLs and Java files? Or am i missing any big part here.
Tried searching with keywords, tags but dint help. Kindly refer if you have any links or thoughts.
Thanks,
Praveen.This can be caused by the 'Function Name' attribute on the page layout region being NULL but with the XML tag still in the page XML i.e.:
<oa:pageLayout id="PageLayoutRN" amDefName="xxjlp.oracle.apps.fnd.por.econtent.server.EContentAM" windowTitle="Portal Guidance Documents" title="Portal Guidance Documents" controllerClass="xxjlp.oracle.apps.fnd.por.econtent.webui.GuidanceDocSumCO" function="">
Check the page you are forwarding to either has a valid value for 'Function Name' or ensure that this tag is removed from the page XML by clicking the 'Set to default' button on the component pallet toolbar.
This is normally caused when a value was added by the developer then removed by highlighting the value and hitting delete. This action keeps the tag in the XML file. You should use the 'Set to default' button which will remove the tag completely. -
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
Maybe you are looking for
-
Hi all, i need to get IBM's JCOP .how can i get it. thanks
-
Reader 10 and 11 keep locking up with Win 8
All of a sudden I cannot open pdf files with Reader 10 or 11. I have tried uninstalling and reinstalling both (separately). Reader 10 will not even start up. Reader 11 will install. I can open it up and (sometimes) open a pdf file through the rea
-
I can't paste nor copy using IDLE with Python 2.7. Can somebody fix the problem
I can't paste nor copy using IDLE with Python 2.7. Can somebody fix the problem
-
How do I divide a long song file?
I have two sound files in my iTunes library which are each about 2 hours in length. If I want to burn them onto an audio CD they obviously are too large for one disc. If I attempt to burn them onto a CD in normal CD audio format, will the beginning o
-
If I import audio books into the music section of itunes it lists the books as albums and all the chapters as tracks fine when I sync them to my ipod classic, but not if I import them as audiobooks and then sync them, any ideas please?