How to unparse the DTD of XML???
Hi
I m using SAXParser and I have to parse an XML that has a DTD how do I ignore the DTD and continue to parse the contents of the XML??
Hello Dave,
your hint was the missing link. I created the class below and now I'm able simly to switch DTD-validation on and off.
Thanks, Rainer
public class UtilXmlResolver implements EntityResolver {
private static boolean m_DisableDtd = false;
public UtilXmlResolver() {
m_DisableDtd = false;
public UtilXmlResolver(boolean DisableDtd) {
m_DisableDtd = DisableDtd;
public InputSource resolveEntity (String publicId, String systemId) {
if (m_DisableDtd) {
return new InputSource(new ByteArrayInputStream(new byte[0]));
} else {
return null;
}
Similar Messages
-
How to avoid the dtd validate of the "iTunes Music Library.xml " when read?
Hi all,
In the article of What are the iTunes library files?("http://docs.info.apple.com/article.html?artnum=93732" ),there is something about the function of "iTunes Music Library.xml " of iTunes.I can get information by reading this xml file.But this file must be validated online(dtd validate).When the net is unconnected,the web exception may be threw.How to avoid the dtd validate of the "iTunes Music Library.xml " when read?Thank you.You can do this with YamiPod (Free)
http://www.yamipod.com/main/modules/downloads/
Or manualy:
Here is a link to where it tells how to do this manualy:
http://discussions.apple.com/message.jspa?messageID=797432#797432 -
How to insert the data from XML to a table
Hi,
I'm using Oracle 10g Express Edition
I need help in How to insert the data from XML file into the table.
Below is the example i'm working on..
I have create ridb user with below mentioned privileges:
Account Status Locked Unlocked
Default Tablespace: USERS
Temporary Tablespace: TEMP
User Privileges :
Roles:
CONNECT
RESOURCE
Direct Grant System Privileges:
CREATE DATABASE LINK
CREATE MATERIALIZED VIEW
CREATE PROCEDURE
CREATE PUBLIC SYNONYM
CREATE ROLE
CREATE SEQUENCE
CREATE SYNONYM
CREATE TABLE
CREATE TRIGGER
CREATE TYPE
CREATE VIEW
& table is created TRIALZIPCODES below mentioned is the DDL:
CREATE TABLE TRIALZIPCODES
STATE_ABBR VARCHAR2(20) NOT NULL
, ZIP_CODE NUMBER(10, 0) NOT NULL
, ZIP_CODE_EXT VARCHAR2(20)
Below is the XML FILE: which is stored in C:\OracleProject Folder
File name: trial.xml
<?xml version="1.0" ?>
<metadata>
- <Zipcodes>
- <mappings Record="4">
<STATE_ABBREVIATION>CA</STATE_ABBREVIATION>
<ZIPCODE>94301</ZIPCODE>
</mappings>
- <mappings Record="5">
<STATE_ABBREVIATION>CO</STATE_ABBREVIATION>
<ZIPCODE>80323</ZIPCODE>
<ZIP_CODE_EXTN>9277</ZIP_CODE_EXTN>
</mappings>
</Zipcodes>
</metadata>
PL/SQL Procedure:which i'm trying to execute from SQLDeveloper
create or replace
PROCEDURE TRIAL AS
BEGIN
DECLARE
-- declare attributes
charString varchar2(80);
finalStr varchar2(4000) := null;
rowsp integer;
v_FileHandle UTL_FILE.FILE_TYPE;
l_context_handle dbms_xmlgen.ctxHandle;
insCtx DBMS_XMLStore.ctxType;
begin
-- DBMS_XMLGEN.setRowTag ( ctx IN ctxHandle, rowTag IN VARCHAR2);
-- DBMS_XMLGEN.setRowSetTag ( ctx IN ctxHandle, rowSetTag IN VARCHAR2);
-- the name of the table as specified in our DTD
DBMS_XMLGEN.SETROWSETTAG(l_context_handle,'zipcodes');
-- the name of the data set as specified in our DTD
DBMS_xmlgen.setRowTag(l_context_handle,'mappings');
-- for getting the output on the screen
dbms_output.enable(1000000);
-- open the XML document in read only mode
v_FileHandle := utl_file.fopen('c:/OracleProject','trial.xml', 'r');
loop
BEGIN
utl_file.get_line(v_FileHandle, charString);
exception
when no_data_found then
utl_file.fclose(v_FileHandle);
exit;
END;
dbms_output.put_line(charString);
if finalStr is not null then
finalStr := finalStr || charString;
else
finalStr := charString;
end if;
end loop;
-- for inserting the XML data into the table
insCtx := DBMS_XMLSTORE.NEWCONTEXT('RIDB.TRIALZIPCODES');
insCtx := DBMS_XMLSTORE.INSERTXML(insCtx, finalStr);
dbms_output.put_line('INSERT DONE '||TO_CHAR(rowsp));
DBMS_XMLStore.closeContext(insCtx);
END;
END TRIAL;
For the first time when i complied i got the errors as :
Procedure RIDB.PROCEDURE1@RIDB
Error(16,14): PLS-00201: identifier 'UTL_FILE' must be declared
Error(16,14): PL/SQL: Item ignored
Error(29,1): PLS-00320: the declaration of the type of this expression is incomplete or malformed
Error(29,1): PL/SQL: Statement ignored
Error(33,1): PL/SQL: Statement ignored
Error(33,19): PLS-00320: the declaration of the type of this expression is incomplete or malformed
Error(36,1): PL/SQL: Statement ignored
Error(36,17): PLS-00320: the declaration of the type of this expression is incomplete or malformed
So i logged in as sys & grant the permission to execute on UTL_FILE to ridb (user):
SQL Statement:
grant execute on utl_file to ridb
So, it got compiled successfully but when i execute it gives me error as:
Source does not have a runnable target.
What does this mean?
So I browse through forum & i got to know that i need to initial the UTL_FILE_DIR ="C:/OracleProject" in init.ora
So can i edit the init.ora with notepad.When i tried to do that it says permission denied
In my system it shows the init.ora file in path C:\oraclexe\app\oracle\product\10.2.0\server\config\scripts
but there is also other file initXETemp in the same path do i need to do the changes in it.
I have tried even editing the SPFILE as mentioned below:
C:\oraclexe\app\oracle\product\10.2.0\server\dbs\SPFILEEXE - I had edit this file using notepad & set the value of UTL_FILE_DIR ="C:/OracleProject". So next time when i restarted i'm unable to log on to the database.
So i had reinstall the software again.
Could you please let me know how to proceed..hi,
I have created the directory from sys database
CREATE or replace DIRECTORY XML_DIR2 AS 'C:\OracleProject';
& grant read,write access to the user
grant read,write on directory XML_DIR2 to RIDB;
& i had change the tag name in the xml file as shown below:
<?xml version = '1.0'?>
<metadata>
<Zipcodes>
<mappings Record="4">
<STABBRE>CA</STABBRE>
<ZIPCODE>94301</ZIPCODE>
</mappings>
<mappings Record="5">
<STABBRE>CO</STABBRE>
<ZIPCODE>80323</ZIPCODE>
<ZIPCODEEXT>9277</ZIPCODEEXT>
</mappings>
</Zipcodes>
</metadata>
TRIALZIPCODE table as shown below:
CREATE TABLE "RIDB"."TRIALZIPCODE"
( "STABBRE" VARCHAR2(20 BYTE),
"ZIPCODE" NUMBER(*,6) NOT NULL ENABLE,
"ZIPCODEEXT" NUMBER
) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
TABLESPACE "USERS" ;
I have tried two methods as shown below:
Procedure 1:
create or replace
PROCEDURE TRIAL_V2 AS
BEGIN
DECLARE
-- declare attributes
charString varchar2(80);
finalStr varchar2(4000) := null;
rowsp integer;
v_FileHandle UTL_FILE.FILE_TYPE;
l_context_handle dbms_xmlgen.ctxHandle;
insCtx DBMS_XMLStore.ctxType;
cnt NUMBER;
xmldoc xmltype := xmltype( bfilename('XML_DIR2','trialxml.xml'), nls_charset_id('AL32UTF8') );
--XML_DIR VARCHAR2(40) := 'C:\\OracleProject';
BEGIN
insCtx := DBMS_XMLStore.newContext('DEV.TRIALZIPCODES');
DBMS_XMLStore.setUpdateColumn(insCtx, 'STABBRE');
DBMS_XMLStore.setUpdateColumn(insCtx, 'ZIPCODE');
DBMS_XMLStore.setUpdatecolumn(insCtx, 'ZIPCODEEXT');
DBMS_XMLStore.setRowTag(insCtx, 'mappings');
cnt := DBMS_XMLStore.insertXML(insCtx, xmldoc);
DBMS_XMLStore.closeContext(insCtx);
END;
Procedure 1 was compiled with out errors but when i execute i got the error as :
Source does not have a runnable target.
Procedure 2_
CREATE OR REPLACE PROCEDURE TRIAL_V3 AS
BEGIN
DECLARE
-- declare attributes
charString varchar2(80);
finalStr varchar2(4000) := null;
rowsp integer;
v_FileHandle UTL_FILE.FILE_TYPE;
l_context_handle dbms_xmlgen.ctxHandle;
insCtx DBMS_XMLStore.ctxType;
cnt NUMBER;
xmldoc xmltype := xmltype( bfilename('XML_DIR2','trialxml.xml'), nls_charset_id('AL32UTF8') );
--XML_DIR VARCHAR2(40) := 'C:\\OracleProject';
BEGIN
INSERT INTO trialzipcode (STABBRE, ZIPCODE, ZIPCODEEXT)
SELECT extractvalue(x.column_value, 'mappings/STABBRE'),
extractvalue(x.column_value, 'mappings/ZIPCODE'),
extractvalue(x.column_value, 'mappings/ZIPCODEEXT')
FROM TABLE(
XMLSequence(
EXTRACT(
xmltype( bfilename('XML_DIR2','trialxml.xml'), nls_charset_id('AL32UTF8') ),
'metadata/Zipcodes/mappings'
) x
END;
END TRIAL_V3;
Procedure 2 was complied without errors but when i execute i got the error as:
Connecting to the database RIDB.
ORA-22288: file or LOB operation FILEOPEN failed
The system cannot find the file specified.
ORA-06512: at "SYS.DBMS_LOB", line 523
ORA-06512: at "SYS.XMLTYPE", line 287
ORA-06512: at "RIDB.TRIAL_V3", line 12
ORA-06512: at line 2
Process exited.
Disconnecting from the database RIDB.
Could you please let me know how to proceed... -
Hi,
I have a file contains the DTD and xml content and I want to get the XML element tree structure together with the element content model.
I usually use DOM to read the XML document, but it seems there no facilities to directly read data from DTD. Is there any way to do that?
And how about generating an empty Document using the DTD?
Thanx a lotGoogle for 'wutka parser'. There's also a few other DTD parsers available. Again google...
cheers,
vidyut -
How to check the element in xml file by xpath
hi all,
* How to check the element in xml file by xpath
for the following XML file,
* I want to check whether
the element (sage) is present or not in the following xml file XPATH expression...
* I have tried by the following expression ,
NodeList result = (NodeList) xpath.evaluate("//*:student/*:sage/text()",xml_dom,XPathConstants.STRING);
System.out.println(result.item(0).getLocalName()); * I want to get the Element sage as String value....
but i am not able to get the element,why that ??? and How to do that ???
MyXML File :
<x:student>
<x:sname>aaa</x:sname>
<x:sage>26</x:sage>
</x:student>
Thanks,
JavaImran<code>* Thanks for reply....
* </code><code>In </code>
<code>x:student element x represents the namespace...thats why i put *:student in my expression....
"//*[local-name() = 'student']/*[local-name() = 'sage']/text()"* By the above code , i am not able to get the sage as string from
</code> resul.item(0).getLocalName() method.......?
* How to get that as string format ? -
How to ignore the DTD in an XML file
I am using XMLReader as
XMLReader parser = XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser");
to parse an xml document. The XML has a <!DOCTYPE ....> in it which specifies a dtd file. If I do not have the dtd file on my local machine, the parser will fail. How can I tell the parser to ignore the <!DOCTYPE..> line, since I do not want it to validate against the dtd anyway?
Thanks.just comment out the <!DOCTYPE> element and you will not have any problem and moreover the default behaviour of xerces is not to validate but see the well formedness .If you want to validate the xml document then do this
parser.setFeature("http://xml.org/sax/features/validation" ,true);
this will validate.
hope this will help you -
How to mention the "dtd" file when loading xml file
i am using the JAXP parser for parsing and loading my xml file.In the file i have mentioned the dtd like
<!DOCTYPE screensmanagement SYSTEM "scrReg.dtd">
But after doing some manipulations, when i save the file through JAXP parser at the same location from where i loaded, then "dtd header" is not saved with my xml File and when i again parse the xml file then parser does not find the "dtd" file coz it is not been saved with xml source.
How can i get aroud this problem.
Merry Chrismiswhen serializing the DOM, use this: transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, scrReg.dtd");
Merry Chrasmas too ;-) -
Hi all,
I learmed the basic stuff of XML, DTD, DOM, etc. long time ago. Now, I came back to resume my XML journey and try to learn the XML Schemas, XPath and XQuery. I have Microsoft SQL Server 2012 Management Studio (SSMS2012) in our computer network. From
Page 221 of the old Book "Beginning XML 2nd Edition" written by David Hunter, et.al., (published by Wrox), I copied the name5.xsd and name5.xml :
<?xml version="1.0"?>
<schema xmlns=http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.wrox.com/name" xmlns:target="http://www.wrox.com/name"
elementFormDefault="qualified">
<element name="name">
<complexType>
<sequence>
<element name="first" type="string"/>
<element name="middle" type="string"/>
<element name="last" type="string"/>
</sequence>
</complexType>
</element>
</schema>
<?xml version="1.0"?>
<name
xmlns=http://www.wrox.com/name"
xmlns:xsi="http://www.wrox.org/2001XMLSchema-instance"
xsi:schemaLocation="http://www.wrox.com/name name5.xsd"
title="Mr.">
<first>John</first>
<middle>Frizgerald</middle>
<last>Doe</last>
</name>
How can I execute these two files in my SSMS2012 for doing my first XML Schema trial?
Please kindly help, advise and respond.
Thanks in advance,
Scott ChangHi Eric Zhang, Thanks for your nice response.
1) I saw the CREATE XML SCHEMA COLLECTION (Transact-SQL) and tried its first example "Create XML schema collection in the database" in my SQL Server 2012 Management Studio (SSMS2012):
-- Create a sample database in which to load the XML schema collection.
-- Copied this set of code stsments from Microsoft Library (ms176009)
-- ColesMS12_20a.sql (saved in C:/Documents/SQL Server Management Studio)
-- 19 March 2015 1145 AM
CREATE DATABASE SampleDB
GO
USE SampleDB
GO
CREATE XML SCHEMA COLLECTION ManuInstructionsSchemaCollection AS
N'<?xml version="1.0" encoding="UTF-16"?>
<xsd:schema targetNamespace="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelManuInstructions"
xmlns ="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelManuInstructions"
elementFormDefault="qualified"
attributeFormDefault="unqualified"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" >
<xsd:complexType name="StepType" mixed="true" >
<xsd:choice minOccurs="0" maxOccurs="unbounded" >
<xsd:element name="tool" type="xsd:string" />
<xsd:element name="material" type="xsd:string" />
<xsd:element name="blueprint" type="xsd:string" />
<xsd:element name="specs" type="xsd:string" />
<xsd:element name="diag" type="xsd:string" />
</xsd:choice>
</xsd:complexType>
<xsd:element name="root">
<xsd:complexType mixed="true">
<xsd:sequence>
<xsd:element name="Location" minOccurs="1" maxOccurs="unbounded">
<xsd:complexType mixed="true">
<xsd:sequence>
<xsd:element name="step" type="StepType" minOccurs="1" maxOccurs="unbounded" />
</xsd:sequence>
<xsd:attribute name="LocationID" type="xsd:integer" use="required"/>
<xsd:attribute name="SetupHours" type="xsd:decimal" use="optional"/>
<xsd:attribute name="MachineHours" type="xsd:decimal" use="optional"/>
<xsd:attribute name="LaborHours" type="xsd:decimal" use="optional"/>
<xsd:attribute name="LotSize" type="xsd:decimal" use="optional"/>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>' ;
GO
-- Verify - list of collections in the database.
select *
from sys.xml_schema_collections
-- Verify - list of namespaces in the database.
select name
from sys.xml_schema_namespaces
-- Use it. Create a typed xml variable. Note collection name specified.
DECLARE @x xml (ManuInstructionsSchemaCollection)
GO
--Or create a typed xml column.
CREATE TABLE T (
i int primary key,
x xml (ManuInstructionsSchemaCollection))
GO
-- ////The following code statements are not used in order to create SampleDB
-- Clean up
---DROP TABLE T
---GO
---DROP XML SCHEMA COLLECTION ManuInstructionsSchemaCollection
---Go
---USE Master
---GO
---DROP DATABASE SampleDB
It worked and I got the following results:
1 4 NULL sys 2009-04-13 12:59:13.390 2012-02-10 20:16:02.097
65536 1 NULL ManuInstructionsSchemaCollection 2015-03-19 11:47:17.660 2015-03-19 11:47:17.660
http://www.w3.org/2001/XMLSchema
http://schemas.microsoft.com/sqlserver/2004/sqltypes
http://www.w3.org/XML/1998/namespace
http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelManuInstructions
But, I don't undertand (i) what SCHEMA COECTION is, (ii) what <xsd:schema targetNamespace=.....</xsd:complexType> are, (iii) How I can specify my "project specific" schema in the Microsoft SCHEMA COLLECTION to check my xml file.
2) I dived in the XQuery programmimng in SSMS2012 in the last few weeks. I used the examles of Ad-Hoc XML File Query by Seth Delconte (in
httpS://www.simple-talk.com/content/print.aspx?article=1756) in my SSMS2012. They worked. But I don't understand the (i) Importing XML data using a function, (ii) Using the XQuery contans()
function to find substrings, (iii)Efficiency comparisons in the article.
Please kindly help me in enlightening me to resolve the difficulties listed in 1) and 2).
Thanks,
Scott Chang -
How to modify the dtd in framemaker?
HI,
I am new recruit for using structured framemaker.
I have a problem need your help. I have a dtd which dose not create from FM. now i want to modify this dtd and then it can be used for FM. how can I get my answer? i will very appreciate if you can show step by step.
thanks a lot!Hi,
DTD is maintained outside of Framemaker. DTD's counterpart in Framemaker is EDD (Element Definition Document), EDD defines the DTD's element structure and attributes from "Framemaker's point of view", so to say. Framemaker is a non-native SGML/XML editor and it does not directly work with SGML/XML-data. EDD, together with Framemaker template document, also defines the formatting of the SGML/XML document
Mapping between DTD and EDD happens through read/write rules. These rules tell Framemaker things like "element xyz is graphic" etc.
Basic EDD
Take a look into online documents "Structure_Dev_Guide.pdf" and "Structure_Dev_Reference.pdf".
Hope this helps,
Martti -
How to read the contents of XML file from my java code
All,
I created an rtf report for one of my EBS reports. Now I want to email this report to several people. Using Tim's blog I implemented the email part. I am sending emails to myself based on the USERID logic.
However I want to email to different people other then me. My email addresses are in the XML file.
From the java program which sends the email, how can I read the fields from XML file. If any one has done this, Please point me to the right examples.
Please let me know if there are any exmaples/BLOG's which explain how to do this(basically read the contents of XML file in the Java program).
Thank You,
PadmaIke,
Do you have a sample. I am searched so much in this forum for samples. I looked on SAX Parser. I did not find any samples.
Please help me.
Thank you for your posting.
Padma. -
CS4- JS : How to change the DTD Option - Reg.
Dear All,
I'm struggle to not getting the answer for change the DTD options though Script.
Here I can Load the DTD using script and Validate then Its showing so many Errors, It means the root element is wrong [DOCTYPE] so the way I can change as per the XML Root Element.
Root Element : Chapter
Load DTD -> DOCTYPE name is : text
//================ Start Coding =================================//
app.doScript(File("D:/program files/Adobe InDesign CS4/Scripts/XML Rules/glue code.jsx"));
var myDoc = app.documents.item(0);
var Store = new Array();
var count=0;
myDTDPath = "C:\\Program Files\\Adobe\\Adobe InDesign CS4\\Executables\\Parser\\Macmil.dtd";
myDoc.importDtd(File(myDTDPath));
main();
function main()
if (app.documents.length != 0)
var myDocument = app.documents.item(0);
//This rule set contains a single rule.
var DTDTitle = new Array (new DTDRootTitle);
with(myDocument)
var elements = xmlElements;
__processRuleSet(elements.item(0), DTDTitle);
else
alert("No open document");
//Adds a return character at the end of every XML element.
function DTDRootTitle()
this.name = "DTDValidation";
//XPath will match on every XML element in the XML structure.
this.xpath = "//chapter";
// Define the apply function.
this.apply = function(elm, myRuleProcessor)
with(elm)
Store[count] = elm.validate();
count+=1;
return true;// Succeeded
} //End of apply function
for(var k=0; k<Store.length; k++)
var test = Store[k];
for(var m=0; m<test.length; m++)
if(test[m].isValid == true)
$.writeln(test[m].element.markupTag.name);
$.writeln(test[m].errorMessage);
//========================== End of the coding ==========================//
Question : 1
Manually I can load the DTD & change the DTD Options as per the Root Element of the XML.
After Validate using Root Element Itself, Its working fine. Zero Errors.
Mean while I can Load DTD though Script but I can't change the DTD Options, through Script.
So Please any one can give me the solution for change the DTD Options using script.
Please any one can give the solution, Really I can appriciate for this...
Hope I'm waiting the result for this query....
Thanks & Regards
T.R.Hairhara Sudhanhello T.R.Hairhara Sudhan
i don't know whether this is write answer or not .
do one thing from active doc get reference of Dtd and from dtd set rootTag = "root tag"
e.g
var dtd = app.activeDocument.dtds[0];
dtd.rootTag = xmlElement.markupTag;
here xmlElement is value for "Validate from" in DTD option
Regards
tahir1987. -
How to register the .DTD file in Oracle Apps
Hi,
I am getting below error while generating XML file by concurrent program:
Attaching XML file and .DTD file.
Do I need to register this .DTD file somewhere?
The XML page cannot be displayed
Cannot view XML input using style sheet. Please correct the error and then click the Refresh button, or try again later.
System error: -2146697210. Error processing resource 'http://mbci-ebsdev.itciss.com/OA_CGI/label.dtd'.
Below is the stored procedure I created to generate the XML file
create or replace
PROCEDURE Demo_XML_Publisher (errbuf VARCHAR2,retcode NUMBER,v_customer_id VARCHAR2)
AS
/*Cursor to fetch Customer Records*/
CURSOR xml_parent
is
SELECT header_id,ordered_item
FROM oe_order_lines_all
WHERE header_id = v_customer_id;
/*Cursor to fetch customer invoice records*/
CURSOR xml_detail(p_customer_id NUMBER)
is
select a.order_number,a.header_id,a.order_type_id
from oe_order_headers_all a,oe_order_lines_all b
where a.HEADER_ID = B.HEADER_ID
and a.header_id = p_customer_id
AND ROWNUM<4;
BEGIN
/*First line of XML data should be <?xml version=”1.0??>*/
FND_FILE.PUT_LINE(FND_FILE.OUTPUT,'<?xml version="1.0" encoding="UTF-8"?>');
FND_FILE.PUT_LINE(FND_FILE.OUTPUT,'<!DOCTYPE labels SYSTEM "label.dtd">');
FND_FILE.PUT_LINE(FND_FILE.OUTPUT,'<labels FORMAT="order.btw" PRINTERNAME="KIMBALL1872A" _QUANTITY="1">' );
FOR v_customer IN xml_parent
LOOP
/*For each record create a group tag <P_CUSTOMER> at the start*/
FND_FILE.PUT_LINE(FND_FILE.OUTPUT,'<label>');
/*Embed data between XML tags for ex:- <CUSTOMER_NAME>ABCD</CUSTOMER_NAME>*/
FND_FILE.PUT_LINE(FND_FILE.OUTPUT,'<HEADER_ID>' || V_CUSTOMER.header_id
|| '</HEADER_ID>');
FND_FILE.PUT_LINE(FND_FILE.OUTPUT,'<ORDERED_ITEM>' || v_customer.ordered_item ||
'</ORDERED_ITEM>');
FOR v_details IN xml_detail(v_customer.header_id)
LOOP
/*For customer invoices create a group tag <P_INVOICES> at the
start*/
FND_FILE.PUT_LINE(FND_FILE.OUTPUT,'<P_INVOICES>');
FND_FILE.PUT_LINE(FND_FILE.OUTPUT,'<variable name= "Order_no">' ||
V_DETAILS.ORDER_NUMBER || '</variable>');
FND_FILE.PUT_LINE(FND_FILE.OUTPUT,'<variable name= "Headr_Id">' ||
V_DETAILS.HEADER_ID || '</variable>');
FND_FILE.PUT_LINE(FND_FILE.OUTPUT,'<variable name= "Order_Type_Id">'||
v_details.order_type_id||'</variable>');
/*Close the group tag </P_INVOICES> at the end of customer invoices*/
FND_FILE.PUT_LINE(FND_FILE.OUTPUT,'</P_INVOICES>');
END LOOP;
/*Close the group tag </P_CUSTOMER> at the end of customer record*/
FND_FILE.PUT_LINE(FND_FILE.OUTPUT,'</label>');
END LOOP;
/*Finally Close the starting Report tag*/
FND_FILE.PUT_LINE(FND_FILE.OUTPUT,'</labels>');
exception when others then
FND_FILE.PUT_LINE(FND_FILE.log,'Entered into exception');
END Demo_XML_Publisher;
Below is the Label.dtd file structure m using:
<!ELEMENT labels (label)*>
<!ATTLIST labels _FORMAT CDATA #IMPLIED>
<!ATTLIST labels _JOBNAME CDATA #IMPLIED>
<!ATTLIST labels _QUANTITY CDATA #IMPLIED>
<!ATTLIST labels _PRINTERNAME CDATA #IMPLIED>
<!ELEMENT label (variable)*>
<!ATTLIST label _FORMAT CDATA #IMPLIED>
<!ATTLIST label _JOBNAME CDATA #IMPLIED>
<!ATTLIST label _QUANTITY CDATA #IMPLIED>
<!ATTLIST label _PRINTERNAME CDATA #IMPLIED>
<!ELEMENT variable (#PCDATA)>
<!ATTLIST variable name CDATA #IMPLIED>
Thanks in AdvanceIn any case, the dtd is incorrect and that may be why. The element structure is at least look like this.
<!ELEMENT labels (label*)>
<!ELEMENT label (CUSTOMER_NAME?, HEADER_ID, ORDERED_ITEM, P_INVOICES*)>
<!ELEMENT P_INVOICES (variable, variable, variable)>If you want to keep some flexibility on variable's cardinality, you can simply it like this.
<!ELEMENT labels (label*)>
<!ELEMENT label (CUSTOMER_NAME?, HEADER_ID, ORDERED_ITEM, P_INVOICES*)>
<!ELEMENT P_INVOICES (variable+)>Then you add the appropriate ATTLIST for the elements. -
How to get the metadata (in xml format) of all the fileds in SQl query ?
Good day ,
I am using the dbms_xmlgen.getXMLfunction to get the result of any query in xml format.
With this XML I also want the metadata information about all the fields used in the query (passed to getXML function). Is it possible and how can I achieve this.
I tried to Google it but couldn't find any solution , it's easy to do it in java where I can get the resultset meta data from the resultset but I have to do it in Oracle function since I want the result in xml format and want to use the oracle XML API.
You may think why I need metadata , the reason is the application will later use this information to sort the data contained in these fields according to their data type provided to.
Regards
Sajjad Ahmed ParachaHi,
Please always say which version of Oracle you're using (SELECT * FROM v$version).
With this XML I also want the metadata information about all the fields used in the query (passed to getXML function). Is it possible and how can I achieve this.It is possible but with a bit of effort.
I would use DBMS_SQL utility to parse the query, extract each column's description and then build a METADATA element with the required information.
Here's an example (11g) :
DECLARE
v_query varchar2(30) := 'select * from scott.emp';
v_cur integer;
v_desc_tab dbms_sql.desc_tab;
v_col_cnt number;
v_col_lst varchar2(4000);
v_xml_query varchar2(32767);
xml_metadata_coll xmlsequencetype := xmlsequencetype();
xml_metadata xmltype;
res clob;
BEGIN
v_cur := dbms_sql.open_cursor;
dbms_sql.parse(v_cur, v_query, dbms_sql.native);
dbms_sql.describe_columns(v_cur, v_col_cnt, v_desc_tab);
dbms_sql.close_cursor(v_cur);
for i in 1 .. v_col_cnt loop
if i > 1 then
v_col_lst := v_col_lst || ', ';
end if;
v_col_lst := v_col_lst || v_desc_tab(i).col_name;
xml_metadata_coll.extend;
select xmlelement("COLUMN"
, xmlattributes(v_desc_tab(i).col_name as "name")
, xmlforest(
case v_desc_tab(i).col_type
when 1 then 'VARCHAR2'
when 2 then 'NUMBER'
when 12 then 'DATE'
when 180 then 'TIMESTAMP'
else 'UNKNOWN'
end as "DATATYPE"
, v_desc_tab(i).col_max_len as "MAX_LENGTH"
, v_desc_tab(i).col_precision as "PRECISION"
, v_desc_tab(i).col_scale as "SCALE"
into xml_metadata_coll(i)
from dual;
end loop;
v_xml_query :=
'SELECT XMLSerialize(document
XMLElement("ROOT"
, :1
, XMLElement("ROWSET"
, XMLAgg(
XMLElement("ROW", XMLForest(' || v_col_lst || '))
) as clob indent
FROM ( ' || v_query || ')';
select xmlelement("METADATA", xmlagg(column_value))
into xml_metadata
from table(xml_metadata_coll)
execute immediate v_xml_query into res using xml_metadata;
dbms_output.put_line(res);
END;
/Ouput :
<ROOT>
<METADATA>
<COLUMN name="EMPNO">
<DATATYPE>NUMBER</DATATYPE>
<MAX_LENGTH>22</MAX_LENGTH>
<PRECISION>4</PRECISION>
<SCALE>0</SCALE>
</COLUMN>
<COLUMN name="ENAME">
<DATATYPE>VARCHAR2</DATATYPE>
<MAX_LENGTH>10</MAX_LENGTH>
<PRECISION>0</PRECISION>
<SCALE>0</SCALE>
</COLUMN>
<COLUMN name="JOB">
<DATATYPE>VARCHAR2</DATATYPE>
<MAX_LENGTH>9</MAX_LENGTH>
<PRECISION>0</PRECISION>
<SCALE>0</SCALE>
</COLUMN>
<COLUMN name="MGR">
<DATATYPE>NUMBER</DATATYPE>
<MAX_LENGTH>22</MAX_LENGTH>
<PRECISION>4</PRECISION>
<SCALE>0</SCALE>
</COLUMN>
<COLUMN name="HIREDATE">
<DATATYPE>DATE</DATATYPE>
<MAX_LENGTH>7</MAX_LENGTH>
<PRECISION>0</PRECISION>
<SCALE>0</SCALE>
</COLUMN>
<COLUMN name="SAL">
<DATATYPE>NUMBER</DATATYPE>
<MAX_LENGTH>22</MAX_LENGTH>
<PRECISION>7</PRECISION>
<SCALE>2</SCALE>
</COLUMN>
<COLUMN name="COMM">
<DATATYPE>NUMBER</DATATYPE>
<MAX_LENGTH>22</MAX_LENGTH>
<PRECISION>7</PRECISION>
<SCALE>2</SCALE>
</COLUMN>
<COLUMN name="DEPTNO">
<DATATYPE>NUMBER</DATATYPE>
<MAX_LENGTH>22</MAX_LENGTH>
<PRECISION>2</PRECISION>
<SCALE>0</SCALE>
</COLUMN>
</METADATA>
<ROWSET>
<ROW>
<EMPNO>7369</EMPNO>
<ENAME>SMITH</ENAME>
<JOB>CLERK</JOB>
<MGR>7902</MGR>
<HIREDATE>1980-12-17</HIREDATE>
<SAL>800</SAL>
<DEPTNO>20</DEPTNO>
</ROW>
<ROW>
<EMPNO>7499</EMPNO>
<ENAME>ALLEN</ENAME>
<JOB>SALESMAN</JOB>
<MGR>7698</MGR>
<HIREDATE>1981-02-20</HIREDATE>
<SAL>1600</SAL>
<COMM>300</COMM>
<DEPTNO>30</DEPTNO>
</ROW>
<ROW>
<EMPNO>7521</EMPNO>
<ENAME>WARD</ENAME>
<JOB>SALESMAN</JOB>
<MGR>7698</MGR>
<HIREDATE>1981-02-22</HIREDATE>
<SAL>1250</SAL>
<COMM>500</COMM>
<DEPTNO>30</DEPTNO>
</ROW>
<ROW>
<EMPNO>7566</EMPNO>
<ENAME>JONES</ENAME>
<JOB>MANAGER</JOB>
<MGR>7839</MGR>
<HIREDATE>1981-04-02</HIREDATE>
<SAL>2975</SAL>
<DEPTNO>20</DEPTNO>
</ROW>
<ROW>
<EMPNO>7654</EMPNO>
<ENAME>MARTIN</ENAME>
<JOB>SALESMAN</JOB>
<MGR>7698</MGR>
<HIREDATE>1981-09-28</HIREDATE>
<SAL>1250</SAL>
<COMM>1400</COMM>
<DEPTNO>30</DEPTNO>
</ROW>
<ROW>
<EMPNO>7698</EMPNO>
<ENAME>BLAKE</ENAME>
<JOB>MANAGER</JOB>
<MGR>7839</MGR>
<HIREDATE>1981-05-01</HIREDATE>
<SAL>2850</SAL>
<DEPTNO>30</DEPTNO>
</ROW>
<ROW>
<EMPNO>7782</EMPNO>
<ENAME>CLARK</ENAME>
<JOB>MANAGER</JOB>
<MGR>7839</MGR>
<HIREDATE>1981-06-09</HIREDATE>
<SAL>2450</SAL>
<DEPTNO>10</DEPTNO>
</ROW>
<ROW>
<EMPNO>7839</EMPNO>
<ENAME>KING</ENAME>
<JOB>PRESIDENT</JOB>
<HIREDATE>1981-11-17</HIREDATE>
<SAL>5000</SAL>
<DEPTNO>10</DEPTNO>
</ROW>
<ROW>
<EMPNO>7844</EMPNO>
<ENAME>TURNER</ENAME>
<JOB>SALESMAN</JOB>
<MGR>7698</MGR>
<HIREDATE>1981-09-08</HIREDATE>
<SAL>1500</SAL>
<COMM>0</COMM>
<DEPTNO>30</DEPTNO>
</ROW>
<ROW>
<EMPNO>7900</EMPNO>
<ENAME>JAMES</ENAME>
<JOB>CLERK</JOB>
<MGR>7698</MGR>
<HIREDATE>1981-12-03</HIREDATE>
<SAL>950</SAL>
<DEPTNO>30</DEPTNO>
</ROW>
<ROW>
<EMPNO>7902</EMPNO>
<ENAME>FORD</ENAME>
<JOB>ANALYST</JOB>
<MGR>7566</MGR>
<HIREDATE>1981-12-03</HIREDATE>
<SAL>3000</SAL>
<DEPTNO>20</DEPTNO>
</ROW>
<ROW>
<EMPNO>7934</EMPNO>
<ENAME>MILLER</ENAME>
<JOB>CLERK</JOB>
<MGR>7782</MGR>
<HIREDATE>1982-01-23</HIREDATE>
<SAL>1300</SAL>
<DEPTNO>10</DEPTNO>
</ROW>
</ROWSET>
</ROOT>A couple of comments :
<li> I handle only four datatypes here (VARCHAR2, NUMBER, DATE, TIMESTAMP). Of course you can add more.
The list of Oracle Type Number is available here : http://docs.oracle.com/cd/E11882_01/server.112/e26088/sql_elements001.htm#i54330
Starting with 11g (not sure which release), DBMS_SQL package also declares these numbers through named constants.
<li> I don't use DBMS_XMLGEN in this example. Instead I rebuild the query using SQL/XML functions and the list of columns that's just been described. -
How to display the data in XML files into JSP using Jdeveloper.
Hi All,
I have two XML files one XML file has the view names and the other has the table names of a particular views, how to display the data in JSP using JDeveloper where when i click a particular view the list of tables of that particular view from XML file two should be displayed in JSP Page.
Are there any reference documents, regarding the above process please can anyone guide through how to do it.Let the servlet ask your business tier to provide the data, then stuff it into beans, and pack those into the Session instance. Then forward the request to the JSP, let the JSP get those beans and display them.
-
How to remove the prolog from XML in Oracle?
Our system works like this:
1. Pass in a piece of XML to the database as a CLOB
2. Database converts this to XMLTYPE (stored as a CLOB (you can skip over this, Marco *{;-) ))
3. An application then reads the XML from the database and inserts it into another bit of XML
4. The application continues its processing based on this new composite XML.
Up until now, the XML loaded into the database in step 1 (by various systems) has never contained a prolog. However, a new system has come along and is now passing in a prolog. This causes problems for the application in step 3.
Aside from trying to get the new system to not pass in the prolog, is there a way to remove it from within Oracle?
The two solutions I've come up with don't feel elegant:
1. Use XMLTABLE to extract the main root node (which could be different, depending on which system sent in the data, and could change)
2. Convert the prolog into a comment, using REPLACE, before converting the CLOB into an XMLTYPE.
If I was forced to use one of these methods, I'd go with 2, but I really, really hope there's a better way of doing it.
Has anyone got any other suggestions, please?
PS. We're currently on 10.2.0.4 and are shortly about to move to 11.2.0.3, but the solution has to work on both versions, for added fun and excitement!This is the error the application gives: "Error obtaining Additional Info SAX Exception : No processing instruction starts with 'xml'" which the app dev says is due to the presence of the prolog in the middle of the xml the app has build up.So basically, the app just "pastes" the XML in the middle of another without caring about the structure? What kind of design is that?
IMO, the app has to be fixed, not the input XML.
Plenty about how to add the prolog, nothing about how to remove it!You can use XMLQuery function to extract the root element :
SQL> create table tmp_xml3 of xmltype
2 xmltype store as basicfile clob;
Table created
SQL> insert into tmp_xml3 values (xmltype('<?xml version="1.0" encoding="UTF-8"?><root/>'));
1 row inserted
SQL> select * from tmp_xml3;
SYS_NC_ROWINFO$
<?xml version="1.0" encoding="UTF-8"?><root/>
SQL>
SQL> select xmlquery('*' passing object_value returning content)
2 from tmp_xml3;
XMLQUERY('*'PASSINGOBJECT_VALU
<root/>
Edited by: odie_63 on 22 août 2012 15:26
Maybe you are looking for
-
Getting the table names in an MS Access database
Hi, I am new to JDBC and making a client/server application that updates a MS Access database through jdbc:odbc. I need to get a list of existing user tables in the db. I have found a great document on the net which has the code, however the code doe
-
Hello I am trying to make a program that counts the number of words in a textfile specified below - later i will make it so you can choose the textfile. When I try to compile this I get the errors: java:23: char cannot be dereferenced
-
Lion has killed my built-in mic for Facetime, but not for Quicktime recording or Skype.
After updating to Lion the built-in mic on my imac doesn't work properly, the person on the other end hears me very faintly. I can't turn it up anywhere. It works fine in Skype, and System Prefs levels are healthy when Facetime isn't running. Please
-
CC App shows LR5 not installed even though it's installed and working
I subscribe to the Photography CC Plan and I went to the CC App today looking for the LR 5.7.1 update. The CC App showed LR5 as being up to date even though LR5 shows its version as 5.7. I quit the CC App to see if that would force it to show the u
-
Can I replace my existng 232 GB Hard Drive with a larger one?
Can I replace my existing 200 GB Hard Drive with a new larger one?