Outputing Results of XML parse
Hi all, i hope im in the right forum, i have managed to access an Xml page and parse the various info i wanted from it and display it, i just wanted to know th easiest to way to save the outout to a word or excel or even text file so i dont lose the info, doesnt have to be fancy, if it could could run and then put all the info in a text file it would be great,
thanks alot
import org.apache.xerces.parsers.DOMParser;
import org.xml.sax.SAXException;
import java.io.IOException;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.w3c.dom.Node;
import org.w3c.dom.NamedNodeMap;
import java.util.Properties;
import java.io.*;
public class IsbnSearch{
public static void main(String args[]) throws IOException, SAXException{
//Check out: http://www.rgagnon.com/javadetails/java-0085.html
Properties systemSettings = System.getProperties();
systemSettings.put("http.proxyHost", "staff-proxy.ul.ie");
systemSettings.put("http.proxyPort", "8080");
System.setProperties(systemSettings);
String s;
BufferedReader reader;
reader = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Please enter Isbn Number\n");
try {
s = reader.readLine();
DOMParser parser = new DOMParser();
parser.parse("http://webservices.amazon.com/onca/xml?Service=AWSECommerceService&Version=2005-03-23&Operation=ItemLookup&ContentType=text%2Fxml&SubscriptionId=0525E2PQ81DD7ZTWTK82&ItemId="+s+"&IdType=ASIN&ResponseGroup=Medium");
Document dom = parser.getDocument();
System.out.println("\nTitle:");
getAttribute(dom, "Title");
System.out.println("\nAuthor:");
getAttribute(dom, "Author");
System.out.println("\nImage:");
getAttribute(dom, "SmallImage");
System.out.println("\nISBN:");
getAttribute(dom, "ISBN");
System.out.println("\nBinding:");
getAttribute(dom, "Binding");
System.out.println("\nReview:");
getAttribute(dom, "URL");
System.out.println("\nDetail Website Please Visit =:");
getAttribute(dom, "DetailPageURL");
System.out.println("\nTime to process Request:");
getAttribute(dom, "RequestProcessingTime");
catch (IOException ioe) {
System.out.println("I/0 Exception Occurresd");
private static void getAttribute(Document dom, String tagName) {
NodeList ItemAttributes = dom.getElementsByTagName(tagName);
for(int i=0;i<ItemAttributes.getLength();i++){
Node aNode = ItemAttributes.item(i);
System.out.println(aNode.getFirstChild().getNodeValue());
NamedNodeMap attributes = aNode.getAttributes();
for (int a=0;a<attributes.getLength();a++){
Node theAttribute = attributes.item(a);
System.out.println(theAttribute.getNodeName() + "="+ theAttribute.getNodeValue());
}
http://java.sun.com/docs/books/tutorial/essential/io/index.html
Similar Messages
-
Using UTL_I18N.ESCAPE_REFERENCE still results in XML Parsing Failed'
Trying to create an RSS feed from a list of newly delivered library materials, and it's all working except for one record with a Turkish character in it. I am trying to convert that value into AL32UTF8 (the database is UTF8) in the XMLElement call, but I still receive errors that the parsing failed at line 24, which is just before the beginning of the loop to aggregate the xmlelements.
Any pointers to what I am doing wrong, conceptually and technically, would be gratefully received, thanks very much for any assistance and/or pointers here.
Peter
create or replace
PROCEDURE "RSSLOOPWORKS2" ( fund_in IN VARCHAR2)
is
-- customizable parameters
l_title varchar2(255) := ' New Titles Since ' || to_char(sysdate - 90, 'MM/DD/YYYY');
l_link varchar2(255) := 'replace this' || fund_in || '.rss';
l_description varchar2(255) := 'This is a feed of changes to items ' || fund_in;
l_language varchar2(255) := 'en-us';
-- end customizable parameters
l_version varchar2(10) := '2.0';
l_clob clob;
l_idx pls_integer := 1;
l_len pls_integer := 255;
l_defrows pls_integer := 100;
l_maxrows pls_integer := 100;
l_desclen pls_integer := 250;
-- for output to file
begin
-- fund := fund_in;
for i in (
select xmlelement( "rss",
-- Begin XML Header Block
xmlattributes( l_version as "version"),
xmlelement( "channel",
xmlforest( l_title as "title",
l_link as "link",
l_description as "description",
l_language as "language"),
-- End XML Header Block
-- Begin List of Individual Articles or Items
xmlagg(
xmlelement( "item",
CASE
WHEN x.title IS NOT NULL THEN xmlelement("title", x.title)
ELSE xmlelement("title", substr(UTL_I18N.ESCAPE_REFERENCE(x.description,'AL32UTF8'),1,255))
END,
xmlelement("link", x.link),
xmlelement("description", UTL_I18N.ESCAPE_REFERENCE(x.description,'AL32UTF8') || ' -- Call number: ' || x.callnum),
xmlelement("callnum", x.callnum),
xmlelement("pubDate", to_char(x.updated_on,'Dy, DD Mon RRRR hh24:mi:ss') || ' EST'),
xmlelement("guid", XMLATTRIBUTES('false' as "isPermaLink"),x.id||to_char(x.updated_on,'JHH24MISS'))
-- End List of Individual Articles or Items
) as result
from ( -- Actual Database Query that populates the list of Items
select id,title,link,description,updated_on, callnum
from drx_rss_feeds
where (fund like fund_in||'%')
and rownum < (l_maxrows+1)) x)
loop
l_clob := xmltype.extract(i.result,'/').getclobval;
exit;
end loop; --i
--- OUTPUT RESULTS
-- for i in 1..ceil(dbms_lob.getlength(l_clob)/l_len) loop
dbms_xslprocessor.clob2file(l_clob, '/iiidb/http/live/screens/rss/', fund_in || '.rss');
-- l_idx := l_idx + l_len;
-- end loop; --i
end rssloopworks2;Is your database characater set AL32UTF8 or UTF8. If it's not AL32UTF8 please convert and try again... Database character set UTF8 is not a complete implementation of XML's UTF-8 encoding.
-
URL in epub results in XML parsing error
Hi
I am using inDesign to create epub ebooks, but stumbling over inserting hyperlinks. Regular hyperlinks to straightforward URLs work OK, but if I add a link to Google maps, like this one...
http://maps.google.co.uk/maps?q=[email protected],0.394&ll=51.443, 0.394&z=17&iwloc=A
... I get problems.
Some ebook readers refuse to load the book, reporting XML parsing error: not well-formed. The red underline points to the second equals symbol. Adobe Digital Editions loads the book, but the hyperlink and everything following it are not displayed.
I have searched for help about this, and gather that XML does not like equals signs. I have tried using percent encoding (%3D) for the second equals sign, but iD appears to insert "25" after the % sign. I even tried using percent encoding for all the reserved characers in the URL (ie :/=@,) but nothing I do seems to fix the problem.
I would really appreciate some help with this. I've run out of ideas.In fact, I don't use XML DB and what I want to do is just to load XML file into the relational table and some parts of whole XML file will be inserted into the CLOB in the table.Why wouldn't you want to use XML DB in 10gR2 to handle XML? I didn't know there was another way. Anyway, you might want to ask this question in this forum.
XML DB -
Mobil.aftonbladet.se results in XML Parsing Error: undefined entity
On Nokia N900.
Was OK before, but now (since friday 27 aug 2010) gives:
XML Parsing Error: undefined entity
Location: http://mobil.aftonbladet.se/
Line number 18, Column 366:
...Hi, thanks for the reply. That site is OK now.
If you have time, check out mobil.dn.se, which gives similar error on my N900:
XML Parsing Error: mismatched tag...
Which sounds like their web-programmers need some basic training. But that site is displayed correctly by Firefox 3.5.6 on my PC. I suppose that version is more tolerant to errors in the web pages? Will the mobile version of Firefox be developed to be more like the PC version in that way? -
ANN: XML Parser for Java v2.0.2.6
The v2.0.2.6 of the XML Parser for Java is now available for download. The following features and bug fixes are included:
Changes:
Conformance to the XSLT/XPATH October REC.
New API in XSLStylesheet class:
removeParam(String param)
resetParams()
Bug fixes:
Bug #1111423: OutOfMemory exception, if multiple calls made to document()
Bug #1101028: Unexpected character error in DTD parsing document using Docbook DTD
Bug #1101021: #default not supported in exclude-result-prefixes
Bug #1099830: Extra characters inserted into output using the XML Parser
Bug #1099663: HTML output does not allow only doctype-public to be specified
Bug #1099536: HTML output does not disable escaping for script, style unless lowercase
Bug #1098738: ArrayOutOfBoundsException xsl:if test="not(@a)'"
Bug #1095047: XSLProcessor NPE'S on named templates with non-empty namespaces
Bug #1094971: XSLStylesheet needs methods for removing parameters
Bug #1092351: Using valueof() shuffles order of elements in my source document
Bug #1086663: xsl:sort data-type attribute can now be a namespace-prefixed name
Bug #1086661: xsl:version attribute now required on literal result element
Bug #1064692: Default xml-serialization should use empty-element syntax
Bug #1064689: Current() function doesn't work correctly
This is the sixth production patch release for v2.
Oracle XML Team http://technet.oracle.com
Oracle Technology Network
nullThe link has been fixed. You will go to the v2 download page
now. Sorry for the inconvience.
Oracle XML Team
http://technet.oracle.com
Oracle Technology Network
Renilton Oliveira (guest) wrote:
: I didn't find the file for version 2.0.0.0 as well.
: Renilton
: Andrei Filimonov (guest) wrote:
: : I tried to download XML Parser for Java v2 it seems that
only
: v
: : 1.0.1.4 is available. Could you please give an exact URL for
: v2
: : download?
: : Andrei Filimonov
: : Oracle XML Team wrote:
: : : The Oracle XML v2 parser is now available for download
here
: as
: : : an early beta release and is written in Java. It features
: an
: : : improved architecture over the Oracle XML v1 parser and
has
: : : shown better performance on small to large XML documents.
: It
: : : will also be able to format the XML document according to
a
: : : stylesheet, having integrated an XSLT processor.
: : : Version 2 of the XML Parser for Java, besides
incorporating
: an
: : : XSLT processor, has been re-architected from version 1.
This
: : has
: : : resulted in a number of changes to the class names
: especially
: : : those that support Namespaces. See v2changes.txt and
: the .diff
: : : difference files in the sample directory.
: : : Oracle XML Team
: : : http://technet.oracle.com
: : : Oracle Technology Network
null -
Xml parsing error while selecting whole result set for sql query
Hi All,
I am having xml parsing error while selecting whole query result set. The data is coming fine for default result set of 50 rows.
My exception is below.
ORA-31011: XML parsing failed
ORA-19202: Error occurred in XML processing
LPX-00234: namespace prefix "xsi" is not declared
Error at line 1
ORA-06512: at "SYS.XMLTYPE", line 254
ORA-06512: at line 1
*31011. 00000 - "XML parsing failed"*
**Cause: XML parser returned an error while trying to parse the document.*
**Action: Check if the document to be parsed is valid.*
My sql query is below that is giving results for default result set of 50 rows.
select extract(xmlType(clob_xml_colm_name), '//v2:node1//childnode/text()','xmlns:v2="namespace_url"').getStringVal() from table_name
My sql developer version is below.
Java(TM) Platform 1.7.0_04
Oracle IDE 3.1.07.42
Versioning Support 3.1.07.42
My database version is below.
Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bit
Please could any one help me urgently as the sql query is supposed to be correct as it is returning query results, but the problem happening when i try to select whole result set.
Thanks and regards,What does the XML look like? It appears that some of the supposed XML stored as a CLOB is not really valid XML. Find the row in the table that is causing your issue and review the "XML" in it.
-
Losing Line-feed in XML parsing (XMLTRANSFORM) or File output (clob2file)?
Hi all, need some help please!
I'm using a xslt file to transferm a XML file into a txt format file. Within the XSLT file, there is a carriage-return (<xsl:text>
</xsl:text>) (it disappeared already, here is what i'm using "#xD" or "#xA", have to take the '&' and ';' away), but the final output txt file seems to lose this carriage-return/line-feed information. The output data became one-line.
Here are the steps I've used:
1. lv_xml_data = XMLTRANSFORM (a.xml_data, b.f_xslt)
=> output data into XMLTYPE;
2. using XMLTYPE.getclobval to get the output data into CLOB format.
lv_output_clob := XMLTYPE.getclobval (lv_xml_data);
3. using encoding:
lv_output_clob :=
DBMS_XMLGEN.CONVERT (lv_output_clob, DBMS_XMLGEN.entity_decode);
4. using clob2file write to a file with txt format.
DBMS_XSLPROCESSOR.clob2file (lv_output_clob,
lv_output_dir,
lv_filename,
NLS_CHARSET_ID ('UTF8')
Been struggling with these a few days already. Any help is appreciated. I would really like to get some input to see what might cause the carriage-return/line-feed characters lost.
Thanks in advance!
-Jane
Edited by: user9084567 on Feb 1, 2010 1:45 PM
Edited by: user9084567 on Feb 1, 2010 1:47 PM
Edited by: user9084567 on Feb 1, 2010 1:48 PMA_non,
After a few testing, I can identify the CRLF was lost in XMLTRANSFORM. I had read your other thread related to this, and try to run this sample code:
/* Formatted on 2010/02/03 15:32 (Formatter Plus v4.8.8) */
DECLARE --Local variables here
v_xml XMLTYPE
:= XMLTYPE
('<
offers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="xsd.xsd"><
submit type="DAM" date="2007-03-28" name="MKTPART1" mode="NORMAL"/><
offer name="Jamestown" flag="true" version_no="1.0"><
standing date="2007-03-29" type="WED"/><
identifier external_id="523736560"/><
/offer><
/offers>'
v_xslt XMLTYPE
:= XMLTYPE
('<
xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <
xsl:output method="text"/> <
xsl:variable name="new_line" select="''
''" /> <
xsl:template match="/"> <
xsl:value-of select="/offers/offer/...name"/><
xsl:value-of select="$new_line" /><
xsl:value-of select="/offers/submit/...date"/><
xsl:value-of select="$new_line" /><
xsl:value-of select="/offers/offer/standing/...date"/><
xsl:value-of select="$new_line" /><
xsl:value-of select="/offers/offer/standing/...type"/><
xsl:value-of select="$new_line" /><
/xsl:template><
/xsl:stylesheet>'
BEGIN -- Test statements here
DBMS_OUTPUT.put_line (XMLTYPE.transform (v_xml, v_xslt).getstringval ());
END;
But come out these error:
Error at line 2
ORA-31011: XML parsing failed
ORA-19202: Error occurred in XML processing
LPX-00230: invalid character 10 (U+000A) found in a Name or Nmtoken
Error at line 4
ORA-06512: at "SYS.XMLTYPE", line 310
ORA-06512: at line 2
Can not figure out why. Try to use this <xsl:variable name="new_line" select="''& # x A ;''" /> inside my style sheet, but it seems not taking it. Not too sure what's exactly should be the quotes for "''& # x A ;''" (w/o space). If I used doub quote + two single quotes, it returns error, LPX-00601: Invalid token in: ' '; if I used single quote + double quote, it did not bring in CRLF at all.
Any input?
Thanks in advance. -
Output query result in XML format
folks:
could anybody provide more information
about how to generate query result in
xml format? looks like DBXML is for demo only
and i have heard that PLSQL XML parser is the way to go; so far i have not found
a sample yet on how to actually
do the XML generation; if you know more
about it, please let me know; thanks in
advance.
BillHere are some sample apps that might interest you:
[list]
[*][url [URL=http://technet.oracle.com/tech/xml/xsql_servlet/index2.htm?Code&files/ffhome.html]The]http://technet.oracle.com/tech/xml/xsql_servlet/index2.htm?Code&files/ffhome.html]The XML Flight Finder
[*][url [URL=http://technet.oracle.com/sample_code/tech/xml/xmlb2b/doc/xb2bhome.html]B2B]http://technet.oracle.com/sample_code/tech/xml/xmlb2b/doc/xb2bhome.html]B2B with XML
[list]
Enjoy,
-rh -
XML Parsing Error: no element found In BI Publisher
Hi Gurus,
I tried to get XML output for a Data Model which was based on SQL queries.
But I got the following error in Firefox
XML Parsing Error: no element found
Location: http://localhost:9704/xmlpserver/servlet/xdo
Line Number 4, Column 1:
In IE I got an other error:
There is no end tag for DATA_SET
Any ideas?
Many thanks
LaszloHi,
I use 11g.
I tried to create element link when I got this error.
Now I am using groupink.
Without using bind variable I got result (Cartesian product)
However if i created and used bind variable I got the same error
this is a dept data set:
select "DEPARTMENTS"."DEPARTMENT_ID" as DEPTNO,
"DEPARTMENTS"."DEPARTMENT_NAME" as "DEPARTMENT_NAME",
"DEPARTMENTS"."LOCATION_ID" as "LOCATION_ID",
"DEPARTMENTS"."MANAGER_ID" as "MANAGER_ID"
from "HR"."DEPARTMENTS" "DEPARTMENTS"
this is the emp data set:
select "EMPLOYEES"."COMMISSION_PCT" as "COMMISSION_PCT",
"EMPLOYEES"."DEPARTMENT_ID" as "DEPARTMENT_ID",
"EMPLOYEES"."EMAIL" as "EMAIL",
"EMPLOYEES"."EMPLOYEE_ID" as "EMPLOYEE_ID",
"EMPLOYEES"."FIRST_NAME" as "FIRST_NAME",
"EMPLOYEES"."HIRE_DATE" as "HIRE_DATE",
"EMPLOYEES"."JOB_ID" as "JOB_ID",
"EMPLOYEES"."LAST_NAME" as "LAST_NAME",
"EMPLOYEES"."MANAGER_ID" as "MANAGER_ID"
from "HR"."EMPLOYEES" "EMPLOYEES"
WHERE "EMPLOYEES"."DEPARTMENT_ID" =:DEPTNO
Thanks for any tip!
Laszlo -
Hi-
I'm trying to use the latest Xercies/Xalan classes in OC4J 10.1.3 as described in the How-To swap XML Parsers document:
http://www.oracle.com/technology/tech/java/oc4j/1013/how_to/how-to-swapxmlparser/doc/readme.html
What I can see happening is that the oracle.xml shared library is successfully 'turned off', but the xalan libraries are not added. Instead, the default xml classes that are distributed with the JDK become visible. For instance, using a slightly modified version of the index.jsp page from the how-to, I get this result:
------ Output from JSP page ----------------
TransformerFactory Instance: org.apache.xalan.processor.TransformerFactoryImpl
Transformer Instance: org.apache.xalan.transformer.TransformerIdentityImpl
Transformer Version: Xalan Java 2.4.1 (!!)
What I expect is for that last line to say version 2.7.0, which is the version of the xalan.jar included in my shared library (code to add that line to the how-to shown below).
I suspect what is happening is that the class loader is simply not letting a shared library override a system library - to do that you probably need to place the jar files in system endorsed directory.
Has anyone gotten this how-to to work - actually replacing the XML parser/transform classes with the latest Xalan classes? Are you sure it is seeing the current version you placed in the shared library?
Thanks,
Eric Everman
---- My modified getXSLTDetails() method in the index.jsp page of the how-to -------
<!-- Additional Import -->
<%@ page import="org.apache.xalan.Version" %>
public static String getXSLTDetails()
Transformer transformer=null;
TransformerFactory transformerfactory = TransformerFactory.newInstance();
Version ver = null;
String br = "<" + "br" + ">"; //otherwise the otn forum chocks on the break.
try
transformer = transformerfactory.newTransformer();
ver = (Version) transformer.getClass().forName("org.apache.xalan.Version").newInstance();
String ret_val =
"TransformerFactory Instance: "+transformerfactory.getClass().getName() + br +
"Transformer Instance: "+transformer.getClass().getName() + br;
if (ver != null) {
ret_val = ret_val + "Transformer Version: " + ver.getVersion() + br;
} else {
ret_val = ret_val + "Transformer Version not Available" + br;
return ret_val;
catch (Exception e)
e.printStackTrace();
return e.getMessage();
}--------------------------------------------------------------------Steve - Thanks for responding on this.
The Xalan SQL extension is built into Xalan. The most painless way to try it out is to run it via JEdit: www.jedit.org
JEdit a OS Java application with a fairly painless install process (I'm assuming you already have a current JRE installed). Once its installed, you'll need to install the XSLT plugin - in JEdit goto Plugins | Plugin Manager | Install and pick the XSLT plugin. You'll need the Oracle JDBC classes on your classpath - this can be done by copying the oracle_jdbc4.jar into the [JEdit install directory]/jars directory.
Restart to load that jar and you should be all set.
I included a sample XSLT page at the bottom of this post that is somewhat of a template transform for the SQL extension - its more complicated then it needs to be, but it does some nice things with the results of the query. Save it as a file and make the appropriate changes to the 'datasource' parameter near the top of the file.
Then in JEdit, open the file and make sure the XSLT plugin is visible (Plugins | XSLT | XSLT Processor Toggle - or alternately dock it in the window via global prefs). In the XSLT plugin: Allow the current buffer to be used as the source, Add that same file as a stylesheet via the '+' button, and pick a result file at the bottom. Then click the 'Transform XML' button.
Troubleshooting: I seem to remember having some classpath errors when I tried this on windows, but others have had it work w/o issues. I do remeber that the XSLT plugin had a popup window that gave a pretty good explaintion of the problem, if it occurs. Also, for some reason the XSLT plugin will not create a new file for the output, so its often best to create a file first, then choose it as the output. Of course, you can always run a transformation from the command line or w/in an applicatoin. Full docs on the Xalan SQL extension can be found at: http://xml.apache.org/xalan-j/extensionslib.html#sql
Here is my sample XSLT transform using the SQL extension:
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:sql="http://xml.apache.org/xalan/sql"
xmlns:str="http://exslt.org/strings"
xmlns:xalan="http://xml.apache.org/xalan"
extension-element-prefixes="sql str xalan">
<xsl:output indent="yes"/>
<xsl:param name="driver">oracle.jdbc.OracleDriver</xsl:param>
<xsl:param name="datasource">jdbc:oracle:thin:jqpublic/jqpublic@server_name:1521:dbname</xsl:param>
<xsl:param name="jndiDatasource"><!-- jndi source for production use w/in enterprise environment --></xsl:param>
<xsl:param name="debug">true</xsl:param>
<xsl:variable name="connection" select="sql:new()"/>
<xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>
<xsl:variable name="lowercase" select="'abcdefghijklmnopqrstuvwxyz'"/>
<!--
The query: You could pass parameters in to this query to build a where clause, but here is a simple example.
Also, its nice to wrap the query with a max row number to prevent huge results.
-->
<xsl:param name="query">
select * from (
SELECT
'One' FIELD_1,
'Two' FIELD_2
FROM DUAL
) where rownum < 100
</xsl:param>
<!-- Essentially, create a XConnection object -->
<xsl:variable name="connection" select="sql:new()"/>
<xsl:template match="/">
<xsl:choose><!-- Connect using JNDI -->
<xsl:when test="$jndiDatasource != ''">
<xsl:if test="not(sql:connect($connection, $jndiDatasource))">
<xsl:message>Failed to connect to db via jndi connection</xsl:message>
<xsl:comment>Failed to connect to db via jndi connection</xsl:comment>
<xsl:if test="$debug = 'true'">
<xsl:copy-of select="sql:getError($connection)/ext-error"/>
</xsl:if>
</xsl:if>
</xsl:when>
<xsl:otherwise><!-- Connect using connection string -->
<xsl:if test="not(sql:connect($connection, $driver, $datasource))">
<xsl:message>Failed to connect to db via driver/url connection</xsl:message>
<xsl:comment>Failed to connect to db via driver/url connection</xsl:comment>
<xsl:if test="$debug = 'true'">
<xsl:copy-of select="sql:getError($connection)/ext-error"/>
</xsl:if>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
<!--
The results of the query. The rowset is brought back in 'streaming' mode,
so its not possible to ask it for the number of rows, or to check for zero
rows. There is a switch to disable streaming mode, but this requires all
rows to be brought into memory.
-->
<xsl:variable name="table" select="sql:query($connection, $query)"/>
<xsl:if test="not($table)">
<xsl:message>Error in Query</xsl:message>
<xsl:copy-of select="sql:getError($connection)/ext-error"/>
</xsl:if>
<page>
<!-- Your xalan environment -->
<xsl:copy-of select="xalan:checkEnvironment()"/>
<!-- Build a bunch of metadata about the rows -->
<meta>
<cols>
<xsl:apply-templates select="$table/sql/metadata/column-header"/>
</cols>
</meta>
<rowset>
<!--
With streaming results, you must use the apply-temmplates contruct,
not for-each, since for-each seems to attempt to count the rows, which
returns zero.
-->
<xsl:apply-templates select="$table/sql/row-set"/>
</rowset>
</page>
<xsl:value-of select="sql:close($connection)"/><!-- Always close -->
</xsl:template>
<xsl:template match="row">
<row>
<xsl:apply-templates select="col"/>
</row>
</xsl:template>
<xsl:template match="column-header">
<col>
<xsl:attribute name="type">
<xsl:value-of select="@column-typename"/>
</xsl:attribute>
<xsl:attribute name="display-name">
<xsl:call-template name="create-display-name"/>
</xsl:attribute>
<xsl:value-of select="@column-name"/>
</col>
</xsl:template>
<!-- Convert column names to proper caps: MY_FIELD becomes My Field -->
<xsl:template name="create-display-name">
<xsl:variable name="col-name">
<xsl:for-each select="str:tokenize(@column-name, '_')">
<xsl:value-of
select="concat(translate(substring(., 1, 1), $lowercase, $uppercase), translate(substring(.,2), $uppercase, $lowercase), ' ')"/>
</xsl:for-each>
</xsl:variable>
<xsl:value-of select="substring($col-name, 1, string-length($col-name) - 1)"/>
</xsl:template>
<!-- Creates data columns named 'col' with a column-name attribute -->
<xsl:template match="col">
<col>
<xsl:attribute name="column-name"><xsl:value-of select="@column-name"/></xsl:attribute>
<xsl:value-of select="."/>
</col>
</xsl:template>
</xsl:stylesheet> -
Hello,
I am using Oracle SOA Suite 11.1.1.4.0 While executing the XQuery example bpel-108-UsingXQuery I am facing the following problem/error.
The Xquery in the example is:
xquery version "1.0";
declare namespace ns0 = "http://example.com/bpel/books";
declare namespace ns1 = "http://samples.otn.com/xquerysample";
declare variable $category as node() external;
declare variable $publisher as xs:string external;
<bookReport>
for $b in //ns0:BOOKS/ns0:ITEM
where data($b/ns0:PUBLISHER) = $publisher
order by string-length($b/TITLE) return
<book>
<author> { data($b/ns0:AUTHOR) } </author>
<title> { data($b/ns0:TITLE) } </title>
<price>{ data(doc("pricelist.xml")/ns1:pricelist/ns1:product[1]/ns1:price) }</price>
<publisher>{ $publisher }</publisher>
{ $category }
</book>
</bookReport>
The variable $publisher, declared in 'declare variable $publisher as xs:string external' shall have the value 'Associated Press' as this has been assigned in the BPEL but it has in fact the value 'oracle.xml.parser.v2.XMLElement@8b8e58'.
The variable $category has the correct value.
What is here wrong or is it a bug in 11.1.1.4.0 in the oracle.xml.parser.v2.XMLElement class.What a mess:
org.w3c.Element element = (org.w3c.Element) payload.get("payload");
private Document writeOraXMLtoDocument(org.w3c.Element payload) throws ParserConfigurationException, SAXException, IOException, TransformerException{
ByteArrayInputStream inputStream = new ByteArrayInputStream(writeXMLToStream(new DOMSource(payload)).toByteArray());
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder =factory.newDocumentBuilder();
return builder.parse(inputStream);
private ByteArrayOutputStream writeXMLToStream(Source source) throws TransformerException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
// Prepare the output file
Result result = new StreamResult(out);
// Write the DOM document to the file
TransformerFactory x = TransformerFactory.newInstance();
Transformer xformer = x.newTransformer();
xformer.transform(source, result);
return out;
Note, that you have to use the oracle transformer located in the xmlparserv2.jar
if it is not your default transformer , you have to set it at least for the above code by System.setProperty("javax.xml.transform.TransformerFactory","..classname..."); -
XML parser error; when XPath elements starts with "_"
Hi,
I have a problem in extracting elements from XML which is starting with "_". please check the queries below executed on Oracle 10g.
Query 1:
SELECT EXTRACTVALUE(XMLTYPE('<A><_B>1</_B><_C>2</_C><_D>3</_D><E>4</E></A>'),'/A/_B') FROM DUAL;
Error starting at line 1 in command:
SELECT EXTRACTVALUE(XMLTYPE('<A><_B>1</_B><_C>2</_C><_D>3</_D><E>4</E></A>'),'/A/_B') FROM DUAL
Error report:
SQL Error: ORA-31011: XML parsing failed
ORA-19202: Error occurred in XML processing
LPX-00601: Invalid token in: '/A/_B'
31011. 00000 - "XML parsing failed"
*Cause: XML parser returned an error while trying to parse the document.
*Action: Check if the document to be parsed is valid.
Query 2:
SELECT EXTRACTVALUE(XMLTYPE('<A><_B>1</_B><_C>2</_C><_D>3</_D><E>4</E></A>'),'/A/E') FROM DUAL;
EXTRACTVALUE(XMLTYPE('<A><_B>1</_B><_C>2</_C><_D>3</_D><E>4</E></A>'),'/A/E')
4
Oracle version:
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
PL/SQL Release 10.2.0.1.0 - Production
CORE 10.2.0.1.0 Production
TNS for 32-bit Windows: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production
Please let me know if there is any workaround for this.*
Thanks,
Veerababu Kanumilli.Hi MichaelS,
- I have executed the queries provided by you, but I am not able to get the result in 10g when I am trying to access elements with "_" in XPath.
select * from v$version where rownum = 1;
select extractvalue (xmltype ('<A><_B>1</_B><_C>2</_C><_D>3</_D><E>4</E></A>'), '/A/_B') "_B" from dual;
select extractvalue (xmltype ('<A><_B>1</_B><_C>2</_C><_D>3</_D><E>4</E></A>'), '/A/E') "E" from dual;
Output:
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
Error starting at line 4 in command:
select extractvalue (xmltype ('<A><_B>1</_B><_C>2</_C><_D>3</_D><E>4</E></A>'), '/A/_B') "_B" from dual
Error report:
SQL Error: ORA-31011: XML parsing failed
ORA-19202: Error occurred in XML processing
LPX-00601: Invalid token in: '/A/_B'
31011. 00000 - "XML parsing failed"
*Cause: XML parser returned an error while trying to parse the document.
*Action: Check if the document to be parsed is valid.
E
4
Thanks,
Veerababu Kanumilli -
Diacritic screwing up XML parsing
Hola -
I've got a procedure which chews through some database input & produces RSS feeds (as taken from a Tyler Muth posting). It started bailing and I traced it down to a particular entry in the table which has a diacritic, which won't be uncommon for me - the name Çınlar seems to cause XML parsing to fail w/the ff. error:
ORA-31011: XML parsing failed
ORA-06512: at "SUPERVISOR.RSSLOOP3", line 30
ORA-06512: at line 1
31011. 00000 - "XML parsing failed"
*Cause: XML parser returned an error while trying to parse the document.
*Action: Check if the document to be parsed is valid.
Questions are: 1) Why would this be, the data is all coming from the same 10gr2 instance; 2) How can I avoid this? The code for the procedure is below, although I assume this is simply a character set/XML parsing issue I'm unfamiliar with. Many, many thanks for any assistance here. I stand perplexed! I know I can scrub the data with translate but I'm hoping there's a better solution, ideally one which allows me to keep all the diacritics in place.
create or replace
procedure rssloop3 ( fund_in IN VARCHAR2)
is
-- customizable parameters
l_title varchar2(255) := ' New Titles Since ' || to_char(sysdate - 90, 'MM/DD/YYYY');
l_link varchar2(255) := 'replace this' || fund_in || '.rss';
l_description varchar2(255) := 'This is a feed of changes to items ' || fund_in;
l_language varchar2(255) := 'en-us';
-- end customizable parameters
l_version varchar2(10) := '2.0';
l_clob clob;
l_idx pls_integer := 1;
l_len pls_integer := 255;
l_defrows pls_integer := 100;
l_maxrows pls_integer := 100;
l_desclen pls_integer := 250;
-- for output to file
fh UTL_FILE.FILE_TYPE;
path VARCHAR2(30);
filename VARCHAR2(30);
begin
path := '/iiidb/http/live/screens/rss/';
filename := fund_in || '.rss';
fh := UTL_FILE.FOPEN(path, filename, 'w');
-- fund := fund_in;
for i in (
select xmlelement( "rss",
-- Begin XML Header Block
xmlattributes( l_version as "version"),
xmlelement( "channel",
xmlforest( l_title as "title",
l_link as "link",
l_description as "description",
l_language as "language"),
-- End XML Header Block
-- Begin List of Individual Articles or Items
xmlagg(
xmlelement( "item",
xmlelement("title", x.title),
xmlelement("link", x.link),
xmlelement("description", x.description),
xmlelement("callnum", x.callnum),
xmlelement("pubDate", to_char(x.updated_on,'Dy, DD Mon RRRR hh24:mi:ss')),
xmlelement("guid", XMLATTRIBUTES('false' as "isPermaLink"),x.id||to_char(x.updated_on,'JHH24MISS'))
-- End List of Individual Articles or Items
) as result
from ( -- Actual Database Query that populates the list of Items
select id,title,link,description,updated_on, callnum
from drx_rss_feeds
where (fund like fund_in||'%')
and rownum < (l_maxrows+1)) x)
loop
l_clob := xmltype.extract(i.result,'/').getclobval;
exit;
end loop; --i
--- OUTPUT RESULTS
for i in 1..ceil(dbms_lob.getlength(l_clob)/l_len) loop
UTL_FILE.PUT_LINE(fh,(substr(l_clob,l_idx,l_len)));
l_idx := l_idx + l_len;
end loop; --i
UTL_FILE.FCLOSE(fh);
end rssloop3;NLS is UTF8 btw.
-
Node refnum comparison (XML parser)
Hello,
I am trying to parse an XML document (actually an Open Office doc) with the LabVIEW 2009 built-in XML Parser. My problem is to identify if two Nodes are actually refering to the same point in the XML or not. For example:
I do a search for specific table cells. The result is an array of Nodes. I want to know if they are on the same table row. So I go up to the first "table row" parent, of which I get the reference. Now I would like to compare two of these parent "row" references, to check if they refer to the same table row. Use of the "equal" LabVIEW function seems not to work (always pretends the reference is different, even if pointing to the same table row actually).
Any idea ?
VincentHello,
Thank you for your interest for the topic. Here is a small example, which is described here:
Assume you have an XML with following content:
<XML>
<Parent>
<Child name="A1">
<Feature />
</Child>
<Child name="A2">
<NoFeature />
</Child>
</Parent>
<Parent>
<Child name="B1">
<Feature />
</Child>
<Child name="B2">
<NoFeature />
</Child>
</Parent>
</XML>
Let's say I need to find all the <Feature> nodes and check whether or not they belong to the same <Parent>. If I look for all the <Feature> nodes by sequentially parsing the whole XML (with a combination of "Next Sibling" and "Next Child" navigation), I will certainly know when I switch from one <Parent> instance to the other one, but this is very inefficient for large XML. I have chosen to use the following method instead:
- with the "Get Elements by Tag Name Array" method for the XML document (DUXGetElementsByTagName), I get an array of all the <Feature> nodes in the document. These are node references to <Child name="A1"/> and <Child name="B2"/> in the above example.
- from both of these nodes I go up to successive parents until I find the <Parent> node reference.
- now I have two different references to <Parent> nodes. I am almost over, I just need to check whether these are the same <Parent> node, or if they are different instances of a <Parent> node (as it is the case in the above example).
How can I do this last step ? Comparing the node references directly with the general "Equal?" built-in LabVIEW function does not work (result is always FALSE, even if both node references point to the same node instance). What is missing here is a sort of "IsSameNode" method, with two node references as inputs, and a boolean as output, that would just return TRUE if both references are pointing to the same node in the XML...
Hope this helps.
Best regards,
Vincent
Attachments:
Demo_XML_Parser.zip 25 KB -
ANN: XML Parser for Java v2.0.2.5
The v2.0.2.5 of the XML Parser for Java is now available for
download. The following features and bug fixes are included:
Conformance to the XSLT/XPATH October PR.
Support for internationalized error messages has been added. The
locale can be set using setLocale(java.util.Locale) function in
XSLProcessor, SAXParser, and DOMParser.
New APIs in XMLNode class:
value-of(String pattern)
selectNodes(String pattern)
selectSingleNode(String pattern)
selectSingleNode(String pattern, NSResolver ns)
New API in XSLStylesheet class
setParam(String param, String value)
Bug fixes:
Bug #957465: Missing a way to set stylesheet-level param-
variables
Bug #962290: selectNodes() improvements
Bug #1033472: Html output prints empty elements for non-empty
elements
Bug #1040717: Character entity for greater that in html output
style
Bug #1046003: Bug is parsing text nodes larger than 16K
Bug #1051671: 'xsl:namespace-alias' not supported
Bug #1052387: Disable-output-escaping doesn't flush while
printing
Bug #1053273: 'xsl:message' terminate attribute not supported
Bug #1058004: No access to media-type and encoding on xsl:output
Bug #1058008: xsl:version attribute not copied to result
Bug #1061159: Exclude-result-prefixes not supported
Bug #1067965: Bug in Non-validating parser while reading QNames
in DTD
This is the fifth production patch release for v2.
Oracle XML Team
http://technet.oracle.com
Oracle Technology Network
nullThe link has been fixed. You will go to the v2 download page
now. Sorry for the inconvience.
Oracle XML Team
http://technet.oracle.com
Oracle Technology Network
Renilton Oliveira (guest) wrote:
: I didn't find the file for version 2.0.0.0 as well.
: Renilton
: Andrei Filimonov (guest) wrote:
: : I tried to download XML Parser for Java v2 it seems that
only
: v
: : 1.0.1.4 is available. Could you please give an exact URL for
: v2
: : download?
: : Andrei Filimonov
: : Oracle XML Team wrote:
: : : The Oracle XML v2 parser is now available for download
here
: as
: : : an early beta release and is written in Java. It features
: an
: : : improved architecture over the Oracle XML v1 parser and
has
: : : shown better performance on small to large XML documents.
: It
: : : will also be able to format the XML document according to
a
: : : stylesheet, having integrated an XSLT processor.
: : : Version 2 of the XML Parser for Java, besides
incorporating
: an
: : : XSLT processor, has been re-architected from version 1.
This
: : has
: : : resulted in a number of changes to the class names
: especially
: : : those that support Namespaces. See v2changes.txt and
: the .diff
: : : difference files in the sample directory.
: : : Oracle XML Team
: : : http://technet.oracle.com
: : : Oracle Technology Network
null
Maybe you are looking for
-
Buffer Busy Waits in a Read-Mostly Database?
11gR2 Standard Edition on Linux x86_64. The database consists of two large tables (12GB+), one column of each of which has an Oracle Text index on it. Once a month, the two tables are refreshed from elsewhere, the Text indexes are updated, and then t
-
Bootcamp 2.0 freezes on install with intel chipset problem solved.
After Days of pulling my hair out trying to figure out why my Windows XP SP2 32 bit would never complete its bootcamp install on Windows. I found the solution to my issue. It may help you. So I decided to post this because I looked everywhere and cou
-
Major issues while editing in FCP7
Hi Folks, I recently got a new Macbook Pro and the only reason for that was to use Final cut pro. now that i have the software and have started editing i have realized that fcp is sosooo slow I mean when i import my video for some basic editing also
-
AR Customer Balances as of any point in time
Does anyone have a script/package to calculate customer balances in AR as of a particular point in time? I know Oracle does it on the fly using the historical information but I was hoping that I didn't have to re-invent the wheel. Thanks
-
After installing iLife '11 DVD, iPhoto is now damaged or incomplete
I have a MacBook Pro purchased in 2011. I am running OS X Lion 10.7.5. iDVD is no longer included with the iLife suite but I was able to purchase an iLife '11 disk which has iDVD on it. When I installed the disk I inadvertently installed everything a