XML into a table??
I am making an application that takes an XML file and puts the content into a table.
I managed to parse the document with a SAX parser so far, but I am not sure how i can put the parsed results into the table, if anyone has done a similar thing, then please help. Some code examples will help a lot.
it is a bit complicated as i will also need a table where its cells can span more than one column.
Where do I begin?
your help is greatly appreciated
JTable? HTML table? Excel table? Something else?
Similar Messages
-
Howto import XML into Excel table ?
Hi,
I asked this before in the Excel forums but received the suggestion that I ask here instead. The question precis : How to ungrey the "Append new data to existing XML lists" checkbox so I can select it when importing XML data into an Excel
spreadsheet.
I have a local server which provides data in XML form and need to import successive reloads of the XML page into successive lines in an Excel spreadsheet. I found the Excel help page entitled "How to use XML in Excel 2003" at http://office.microsoft.com/en-gb/excel-help/how-to-use-xml-in-excel-2003-HA001101964.aspx?CTT=1&origin=EC001022986
which was useful in so far as permitting me to import the data using the XML Source task pane and mapping the elements I need from the XML source to columns in the spreadsheet.
In order to append successive lines from the XML source page, as I understand it from the link I quoted, I need to change the XML Map properties to "Append new data to existing XML lists". However this checkbox is greyed out in the
XML Map properties dialog box so I can't select it.
Any ideas how I can achieve my aims here ?
Thanks in advance,
MikeHi Mike,
Thank you for contacting Office IT Pro General Discussions Services.
From your description, I understand that you tried to import XML into Excel table. You selected “Use the XML Source
task pane” when opening the XML file, then you tried to check the option in the
Map Properties window: "Append new data to existing XML lists".
However, this option is grayed out. If there is any misunderstanding, please feel free to let me know.
I have checked the issue on my side but could not reproduce this issue. I suggest download the sample XML file as suggested on the page and test the
issue again:
http://www.microsoft.com/downloads/details.aspx?FamilyId=B4BD3283-AD0B-408D-9CE7-AB9C3537BBBB&displaylang=en
If the problem does not occur with the sample XML file, this issue might occur as there are some problems with the XML you were using.
If the problem also occurs in with the sample XML file, this issue might be related to some third-party software conflicts. I suggest checking this
issue by starting Excel in the safe mode.
Start the Office program in safe mode
==============
1.
Click Start, point to All Programs, and then point to
Microsoft Office.
2.
Press and hold the CTRL key, and then click
Microsoft Excel.
If the problem does not occur in the safe mode, this issue might be related to some third-party add-ins in the Excel program, we can try to disable
them. Normally, you could do the following to disable the conflict add-ins in your Excel program:
Disable add-ins
Click
Tools > Options >
Add-in, click Go button in the Manage:
Com-in Add.
Check if there are any add-ins,
clear the checkbox to disable them.
Close the Office program and
restart it.
Add one check back each time to the list of Add-In,
restart the Office program, and repeat the above procedure. Once the issue reappears again, we can determine which add-in causes this problem and then disable it.
Please take your time to try the suggestions and let me know the results at your earliest convenience. If anything is unclear or if there is anything
I can do for you, please feel free to let me know.
Best Regards,
Sally Tang -
Can't Figure Out How To Import XML into a Table?
HELP!
I've been using InDesign for several years now... but everything Ive ever done has been basic one off layout concepts.
I am working on a website for a musical theater actress and for her resume, Id like to make a PDF which lists in table format the show, theatre and role she had for each job.
I could do this manually... but Id really like to learn how to just reuse the same XML data that I have for her website and import it into InDesign.
I have looked at Adobe's help file, I have scoured the internet, and I still can't figure it out... I have done like the adobe support file says... and I cant seem to get the values I create in her resume xml file to show up in a table I create in InDesign.
I even tried to simplify it for the learning process and did something as basic as an XML file that has 5 colors... couldnt even get that working.
So could someone explain it to me like Im a 5 year old... how to take a XML file, import it, place it in a table and have the data actually show up in the table.
thanks,
brianAre you sure you want to use XML with tables for this? No doubt importing XML into tables is useful for some specialized tasks, such as importing formatting information inside the XML itself, but for most of the familiar tasks that XML excels at, tables are neither necessary nor useful.
In my (limited) experience, if the XML elements are well-differentiated, by which I mean different types of data have their own distinctive tags, then the special powers of XML can be exploited more fully using the more familiar tagged text, nested tags etc. in ordinary text frames using paragraph breaks, tab characters, etc. to achieve a suitably "tabular" finished appearance.
If you must import XML into tables, I recommend Adobe's own PDF "Adobe InDesign CS3 and XML: A Technical Reference" availabe here:
http://www.adobe.com/designcenter/indesign/articles/indcs3ip_xmlrules.pdf
It sounds very daunting -- the words "technical reference" make me shudder -- but actually it's very readable and not very technical at all. Some nice pics and everything!
Jeremy -
Transforming XML into Internal Table
Hi guys, I have tried a simple nested code but i fail to write in the Name, Phone and Email portion ... I manage to get to the header level... Can any one gimme some pointers?
PS: I have read to those threads posted here already before I got this far
<b><u>MAIN CODE</u></b>
REPORT ZTESTJASON11.
TYPES: BEGIN OF T_HEADER,
NAME(140),
PHONE(23),
EMAIL(100),
END OF T_HEADER,
D_HEADER TYPE T_HEADER OCCURS 0.
TYPES: BEGIN OF T_ITEM,
HEADER TYPE D_HEADER,
END OF T_ITEM,
D_ITEM TYPE T_ITEM OCCURS 0.
TYPES: BEGIN OF T_LIST,
ITEM TYPE D_ITEM,
END OF T_LIST,
D_LIST TYPE T_LIST OCCURS 0.
TYPES: BEGIN OF TYPE_DATA,
LIST TYPE D_LIST,
END OF TYPE_DATA.
DATA: RESPONSE TYPE TABLE OF TYPE_DATA.
DATA: XMLOUT TYPE STRING.
DATA: ITAB LIKE SOLI OCCURS 0 WITH HEADER LINE.
DATA: HEADER_WA TYPE T_HEADER,
HEADER_LN TYPE D_HEADER,
ITEM_WA TYPE T_ITEM,
ITEM_LN TYPE D_ITEM,
LIST_WA TYPE T_LIST,
LIST_LN TYPE D_LIST.
MOVE: 'JIM BEAN' TO HEADER_WA-NAME,
'+6512345678' TO HEADER_WA-PHONE,
'[email protected]' TO HEADER_WA-EMAIL.
APPEND HEADER_WA TO HEADER_LN.
ITEM_WA-HEADER = HEADER_LN.
APPEND ITEM_WA TO ITEM_LN.
LIST_WA-ITEM = ITEM_LN.
APPEND LIST_WA TO LIST_LN.
myXML-LIST = LIST_LN.
PERFORM UPLOAD_XML.
FORM UPLOAD_XML .
REFRESH ITAB.
clear RESPONSE.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = 'C:test11.XML'
filetype = 'BIN'
TABLES
data_tab = ITAB.
LOOP AT ITAB.
CONCATENATE XMLOUT ITAB-LINE INTO XMLOUT.
ENDLOOP.
CALL TRANSFORMATION ('ZTEST11X2A')
SOURCE XML XMLOUT
RESULT RESPONSE = RESPONSE.
BREAK-POINT.
ENDFORM.
<b><u>XML CODE (test11.xml)</u></b>
<?xml version="1.0" encoding="iso-8859-1"?>
<myXML>
<LIST>
<ITEM>
<HEADER>
<NAME>JIM BEAN</NAME>
<PHONE>+6512345678</PHONE>
<EMAIL>[email protected]</EMAIL>
</HEADER>
</ITEM>
</LIST>
</myXML>
<b><u>XSLT CODE (ZTEST11X2A)</u></b>
<xsl:transform version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:sap="http://www.sap.com/abapxml"
>
<xsl:template match="/">
<asx:abap xmlns:asx="http://www.sap.com/abapxml">
<asx:values>
<RESPONSE>
<myXML>
<LIST>
<ITEM>
<xsl:for-each select="ITEM">
<I>
<HEADER>
<NAME> <xsl:value-of select="NAME"/> </NAME>
<PHONE> <xsl:value-of select="PHONE"/> </PHONE>
<EMAIL> <xsl:value-of select="EMAIL"/> </EMAIL>
</HEADER>
</I>
</xsl:for-each>
</ITEM>
</LIST>
</myXML>
</RESPONSE>
</asx:values>
</asx:abap>
</xsl:template>
</xsl:transform>Thanks a million in advance Raja, thanks for ur help, realli appreaciate it! ")
Here it is...
<u><b>MAIN CODE (itab declaration)</b></u>
REPORT ZTESTJASON11.
TYPES: BEGIN OF T_HEADER,
NAME(140),
PHONE(23),
EMAIL(100),
END OF T_HEADER,
D_HEADER TYPE T_HEADER OCCURS 0.
TYPES: BEGIN OF T_ITEM,
HEADER TYPE D_HEADER,
END OF T_ITEM,
D_ITEM TYPE T_ITEM OCCURS 0.
TYPES: BEGIN OF T_LIST,
ITEM TYPE D_ITEM,
END OF T_LIST,
D_LIST TYPE T_LIST OCCURS 0.
TYPES: BEGIN OF TYPE_DATA,
LIST TYPE D_LIST,
END OF TYPE_DATA.
DATA: RESPONSE TYPE TABLE OF TYPE_DATA.
DATA: XMLOUT TYPE STRING.
DATA: ITAB LIKE SOLI OCCURS 0 WITH HEADER LINE.
DATA: HEADER_WA TYPE T_HEADER,
HEADER_LN TYPE D_HEADER,
ITEM_WA TYPE T_ITEM,
ITEM_LN TYPE D_ITEM,
LIST_WA TYPE T_LIST,
LIST_LN TYPE D_LIST.
MOVE: 'JIM BEAN' TO HEADER_WA-NAME,
'+6512345678' TO HEADER_WA-PHONE,
'[email protected]' TO HEADER_WA-EMAIL.
APPEND HEADER_WA TO HEADER_LN.
ITEM_WA-HEADER = HEADER_LN.
APPEND ITEM_WA TO ITEM_LN.
LIST_WA-ITEM = ITEM_LN.
APPEND LIST_WA TO LIST_LN.
myXML-LIST = LIST_LN.
PERFORM UPLOAD_XML.
FORM UPLOAD_XML .
REFRESH ITAB.
clear RESPONSE.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = 'C:test11.XML'
filetype = 'BIN'
TABLES
data_tab = ITAB.
LOOP AT ITAB.
CONCATENATE XMLOUT ITAB-LINE INTO XMLOUT.
ENDLOOP.
CALL TRANSFORMATION ('ZTEST11X2A')
SOURCE XML XMLOUT
RESULT RESPONSE = RESPONSE.
BREAK-POINT.
ENDFORM.
<u><b>XML CODE (test11.xml)</b></u>
<?xml version="1.0" encoding="iso-8859-1"?>
<myXML>
<LIST>
<ITEM>
<HEADER>
<NAME>JIM BEAN</NAME>
<PHONE>+6512345678</PHONE>
<EMAIL>[email protected]</EMAIL>
</HEADER>
</ITEM>
</LIST>
</myXML>
<u><b>XSLT CODE (ZTEST11X2A)</b></u>
<xsl:transform version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:sap="http://www.sap.com/abapxml"
>
<xsl:template match="/">
<asx:abap xmlns:asx="http://www.sap.com/abapxml">
<asx:values>
<RESPONSE>
<myXML>
<LIST>
<ITEM>
<xsl:for-each select="ITEM">
<dataset1>
<HEADER>
<xsl:for-each select="HEADER">
<dataset2>
<NAME>
<xsl:value-of select="NAME"/>
</NAME>
<PHONE>
<xsl:value-of select="PHONE"/>
</PHONE>
<EMAIL>
<xsl:value-of select="EMAIL"/>
</EMAIL>
</dataset2>
</xsl:for-each>
</HEADER>
</dataset1>
</xsl:for-each>
</ITEM>
</LIST>
</myXML>
</RESPONSE>
</asx:values>
</asx:abap>
</xsl:template>
</xsl:transform> -
Help needed to load XML into DB table
I need some serious help if someone can spare the time. I am completely new to XML and don't really understand it yet but I need to be able to load an XML file (example) below.
I want to load this into a table that would look like the following:
CHAPTER_TITLE DOC_HTML DOC_TITLE
Men's Health 494440 AAAAA
Men's Health 496812 BBBBB
etc....
<?xml version=1.0 encoding=utf-8?>
<BookCollections Quantity=1 Title=Emis Books Collection>
<Book Folder=PILSS Title=Patient Support>
<Chapter Title=Men''s Health>
<Document DocHTML=494440 Title=AAAAA />
<Document DocHTML=496812 Title=BBBBB />
<Document DocHTML=498923 Title=CCCCC />
<Document DocHTML=499844 Title=DDDDD />
<Document DocHTML=499901 Title=EEEEE />
</Chapter>
</Book>
</BookCollections>I have read through the documentation I could find but I can't get it to work. I had a simple procedure which loaded the text file as a CLOB and then inserted it into an XMLTYPE column but even that wouldn't work. I would rather it loaded as above in seperate columns.
Is there a simple example someone can help me out with?That is very close ORA_SID thank you. But I get the ORA-19025 error when I have more than one Chapter section. The example was a cut down version, ther real file has thousands of Chapters.
e.g.
1 insert into test2 values(xmltype(' <BookCollections Quantity="1" Title="Emis Books Collection">
2 <Book Folder="PILSS" Title="Patient Support">
3 <Chapter Title="Men''s Health">
4 <Document DocHTML="494440" Title="AAAAA" />
5 <Document DocHTML="496812" Title="BBBBB" />
6 <Document DocHTML="498923" Title="CCCCC" />
7 <Document DocHTML="499844" Title="DDDDD" />
8 <Document DocHTML="499901" Title="EEEEE" />
9 <Document DocHTML="500381" Title="FFFFF" />
10 <Document DocHTML="500446" Title="GGGGG" />
11 <Document DocHTML="500996" Title="HHHHH" />
12 </Chapter>
13 <Chapter Title="Contraception">
14 <Document DocHTML="496815" Title="IIIII" />
15 <Document DocHTML="496817" Title="JJJJJ" />
16 <Document DocHTML="499547" Title="KKKKK" />
17 <Document DocHTML="499550" Title="LLLLL" />
18 <Document DocHTML="500473" Title="MMMMM" />
19 <Document DocHTML="500704" Title="NNNNN" />
20 <Document DocHTML="500813" Title="OOOOO" />
21 <Document DocHTML="500995" Title="PPPPP />
22 <Document DocHTML="500996" Title="QQQQQ" />
23 </Chapter>
24 </Book>
25 </BookCollections>
26* '))
SQL> /
1 row created.
SQL> SELECT extractValue(xml_data, '/BookCollections/Book/Chapter/@Title') AS Chapter_Title,
2 extractValue(value(em), '/Document/@DocHTML') AS Document_DocHTML,
3 extractValue(value(em), '/Document/@Title') AS Document_Title
4 FROM test2,table(XMLSequence(extract(xml_data,'/BookCollections/Book/Chapter/Document'))) em
5 ;
FROM test2,table(XMLSequence(extract(xml_data,'/BookCollections/Book/Chapter/Document'))) em
ERROR at line 4:
ORA-19025: EXTRACTVALUE returns value of only one nodeCan you help on this? -
This is my first thread so I hope I have formatted my request appropriately...
If I have a simple XML doc with several records (see below) what is the best / easiest way to insert the data into multiple tables (Oracle 10g Release 1)?
For example 3 tables:
PATIENT table (CLAIMID, FNAME, LNAME, HEALTHNUM)
ADDRESS table (CLAIMID, STREET, CITY, PROVINCE)
SERVICE table (CLAIMID, SERVICE, ADMITDATE, DEPARTDATE)
<?xml version="1.0"?>
<CLAIMS>
<CLAIM>
<CLAIMID>1</CLAIMID>
<FNAME>Oscar</FNAME>
<LNAME>Grouch</LNAME>
<HEALTHNUM>1234657890</HEALTHNUM>
<STREET>123 Sesame Street</STREET>
<CITY>Sesameville</CITY>
<PROVINCE>ON</PROVINCE>
<SERVICE>Heart Surgery</SERVICE>
<ADMITDATE>2007-06-05</ADMITDATE>
<DEPARTDATE>2007-06-11</DEPARTDATE>
</CLAIM>
<CLAIM>
<CLAIMID>2</CLAIMID>
<FNAME>Poppa</FNAME>
<LNAME>Smurf</LNAME>
<HEALTHNUM>0987654321</HEALTHNUM>
<STREET>44 Blue Street</STREET>
<CITY>Smurfville</CITY>
<PROVINCE>ON</PROVINCE>
<SERVICE>Lung Transplant</SERVICE>
<ADMITDATE>2007-05-28</ADMITDATE>
<DEPARTDATE>2007-06-04</DEPARTDATE>
</CLAIM>
...more <CLAIM> records
</CLAIMS>
I can import the XML document into an XMLType column but don't know where to go from there...
The extractValue method seems to work only when there is a single claim record in the XML document but a typical document will contain several hundred claims.
Thanks in advance,
M KentUse the Oracle Berkeley DB XML to store the XML document in a embedded xml database. To store in the Oracle 10g database use XSU. With XSU an XML document may also be stored in multiple tables.
http://download-east.oracle.com/docs/cd/A97329_03/web.902/a88894/adx07xsu.htm#1016732 -
Loading xml into relational tables.
I was wondering if anyone knows of a product/libraries which does the following:
-Read data from a relational Database (multiple tables) and generate XML files based upon an XML Schema or DTD file?
-Read XML files and load data into a relational Database.
-Graphical Interface for performing the maps (perhaps based upon .xslt). ie.... Mapping of the XML Schema to Multiple Database Tables, Performing Joins etc...
-Ability to connect to any type of Relational database (not just Oracle). Which rules out XML DB.This product does look to be ok, however it is missing a couple features that I would like the product to have.
I would like this product to be able to insert/update data across multiple tables. Being able to do such things as generate foreign key relationships.
It doesn't seem as though the XML being generated can be customized very easily. Some XML formats I deal with are very complex (such as X12/EDI).
I would really like a graphical mapper.
Here is a note from the doc:
Storing XML Data Across Tables
Currently the XML SQL Utility (XSU) can only store data in a single table. It maps a canonical representation of an XML document into any table or view. But there is a way to store XML with XSU across tables. You can do this using XSLT to transform any document into multiple documents and insert them separately. Another way is to define views over multiple tables (using object views if needed) and then do the insertions into the view. If the view is inherently non-updatable (because of complex joins), then you can use INSTEAD OF triggers over the views to do the inserts.
This product looks really good, I was hoping that Oracle had something comparable:
http://www.hitsw.com/products_services/xml_platform/allora.html -
Generate xml from a table and insert the xml into another table
I want to generate an xml file from a table and insert it into another table all in one tsql
insert into table B(xmlfile)
select * from tableA
FOR
XML
PATH('ac'),TYPE,ELEMENTS
XSINIL,ROOT('Accum')
Is not working any helpI have solved my issue all I did was to change my column datatype to xml
-
How to import XML into SQL Table
Dear all,
There are a lot of books about exporting data into XML format.
Actually, how to use XML Documents? Sorry I am new that I ask such a question.
What i think may be exchange or save data using xml. If so, How to import into MS SQL table? Do it need to do any mapping?
Appreciate for your hintsAre you sure you want to use XML with tables for this? No doubt importing XML into tables is useful for some specialized tasks, such as importing formatting information inside the XML itself, but for most of the familiar tasks that XML excels at, tables are neither necessary nor useful.
In my (limited) experience, if the XML elements are well-differentiated, by which I mean different types of data have their own distinctive tags, then the special powers of XML can be exploited more fully using the more familiar tagged text, nested tags etc. in ordinary text frames using paragraph breaks, tab characters, etc. to achieve a suitably "tabular" finished appearance.
If you must import XML into tables, I recommend Adobe's own PDF "Adobe InDesign CS3 and XML: A Technical Reference" availabe here:
http://www.adobe.com/designcenter/indesign/articles/indcs3ip_xmlrules.pdf
It sounds very daunting -- the words "technical reference" make me shudder -- but actually it's very readable and not very technical at all. Some nice pics and everything!
Jeremy -
SSIS ETL Import XML into SQL Tables
HI,
I am trying to import the below shown sample file data into sql tables using SSIS. Could you please guide on how to import data
Metadata={A=@RefID, B=CH_ERT_ID, C=CH_DATE_ADDED, D=CH_DATE_DELETED, E=CH_SOURCE_TABLE, F=CH_SOURCE_ID, G=CH_FIRST_NAME, H=CH_MIDDLE_NAME, I=CH_LAST_NAME, J=CH_NAME_SUFFIX, K=CH_BIRTH_DATE, L=CH_BIRTH_ORDER, M=CH_DEATH_DATE, N=CH_STREET_ADDRESS, O=CH_CITY,
P=CH_STATE, Q=CH_ZIP, R=CH_PHONE, S=CH_MOTHERS_MAIDEN_LAST, T=CH_MOTHERS_MAIDEN_FIRST, U=CH_GENDER}
Initial RefID CoDoSA Identity
ITBSQUVY3UD7M89W OysterID: ITBSQUVY3UD7M89W
Creation Date: null
Size: 1
CType: N
Persistant: false
Record 0: @RefID=source1.2, CH_DATE_ADDED=2014-05-27 12:05:00.87, CH_SOURCE_TABLE=sample, CH_SOURCE_ID=151001, CH_FIRST_NAME=xx, CH_LAST_NAME=xx, CH_BIRTH_DATE=2003-07-05 00:00:00.0, CH_STREET_ADDRESS=2478 S 13th st, CH_CITY=xx, CH_STATE=xx, CH_ZIP=xx CH_GENDER=F,
Input record: false, Current Traces: OID: ITBSQUVY3UD7M89W, RunID: 1, Rule: [@], Previous Traces: []
Merges: {}
StrToStr: []
NegStrToStr: []
T6RGLWXTUL7JT4LK OysterID: T6RGLWXTUL7JT4LK
Creation Date: null
Size: 1
CType: N
Persistant: false
Record 0: @RefID=source1.5, CH_DATE_ADDED=2014-05-27 12:05:00.87, CH_SOURCE_TABLE=sample, CH_SOURCE_ID=151015, CH_FIRST_NAME=xx, CH_MIDDLE_NAME=I, CH_LAST_NAME=xx, CH_BIRTH_DATE=2003-06-21 00:00:00.0, CH_STREET_ADDRESS=N128 W20158 HOLY HILL RD, CH_CITY=x, CH_STATE=x,
CH_ZIP=x, CH_GENDER=M, Input record: false, Current Traces: OID: T6RGLWXTUL7JT4LK, RunID: 1, Rule: [@], Previous Traces: []
Merges: {}
StrToStr: []
NegStrToStr: []In your case the file needs to be transposed (rows to columns), likely you'll need to transform the data using a pre-processing step outside SSIS.
I suspect another option could be to load the file as a whole using a Flat File Source that defines a single large column (typically a DT_STR set to its max size, if the file sure fits in completely) and then you can use a Conditional Split Transform. to
take each row (based on lengths if fixed) and write to another file this time in tabular format.
Arthur
MyBlog
Twitter -
Hello All,
I need to load many XML files into their own tables without using the XMLType column type. We need each element/attribute to get it's own column. For example
<book id="bk103">
<genre>Mystery</genre>
</book>
should load to a table with columns ID, GENRE of type varchar2. I have 1000s of XML files that need to be loaded, each with different data/structure. Ideally, I want to be able to point a SP at a folder that contains, say 250 XML files, run it, then have it create 250 tables each with a column set corresponding to each element/attribute from the XML file. Given that each XML file has a different structure, I need a solution that does not require a table to already exist. A solution that figures it out on the fly, perhaps using the VARCHAR2 type for all columns, would be best. I did notice this post, but it first requires the table to already exist. Is there a way to load 1 or more XML files into their own table with non XMLType datatypes where each table is created on the fly?
Any help appreciated,
TIA
Rob
Edited by: user10729248 on Dec 19, 2008 6:13 AM
Edited by: user10729248 on Dec 19, 2008 6:14 AMThanks for the response but I am not finding the information helpful. The examples provided assume the table into which the XML file is loaded already exists or a CREATE TABLE script is run. I need a solution that creates the table automagically. Can someone provide an example of this please? Also, I'm looking for a PL/SQL SP-based solution if this is possible. Many of the examples use Java; we're using .NET.
-
Hi,
How can I read an xml.file read in an oracle table (invoice varchar2(20), invoice_line number, ship_date date, country varchar2(100))?
The xml looks like this:
<?xml version="1.0" encoding="utf-8" ?>
- <dataset xmlns="http://developer.cognos.com/schemas/xmldata/1/" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance">
- <!--
<dataset
xmlns="http://developer.cognos.com/schemas/xmldata/1/"
xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
xs:schemaLocation="http://developer.cognos.com/schemas/xmldata/1/ xmldata.xsd"
>
-->
- <metadata>
<item name="Invoice #" type="xs:string" length="42" />
<item name="Invoice Line" type="xs:string" length="10" />
<item name="Ship Date" type="xs:date" />
<item name="COUNTRY" type="xs:string" length="8" />
</metadata>
- <data>
- <row>
<value>26623</value>
<value>0001</value>
<value>2010-05-03</value>
<value>USA</value>
</row>
- <row>
<value>26624</value>
<value>0001</value>
<value>2010-05-03</value>
<value>USA</value>
</row>
- <row>
<value>26624</value>
<value>0003</value>
<value>2010-05-03</value>
<value>USA</value>
</row>
- <row>
<value>26625</value>
<value>0001</value>
<value>2010-05-03</value>
<value>USA</value>
</row>
</data>
</dataset>
Thnx, RobbertHi,
Possible solutions will depend on your db version, which you didn't give.
The following example assumes you're using 10gR2 :
CREATE TABLE invoices (
invoice varchar2(20),
invoice_line number,
ship_date date,
country varchar2(100)
DECLARE
xmldoc xmltype := xmltype(
'<?xml version="1.0" encoding="utf-8" ?>
<dataset xmlns="http://developer.cognos.com/schemas/xmldata/1/" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance">
<metadata>
<item name="Invoice #" type="xs:string" length="42" />
<item name="Invoice Line" type="xs:string" length="10" />
<item name="Ship Date" type="xs:date" />
<item name="COUNTRY" type="xs:string" length="8" />
</metadata>
<data>
<row>
<value>26623</value>
<value>0001</value>
<value>2010-05-03</value>
<value>USA</value>
</row>
<row>
<value>26624</value>
<value>0001</value>
<value>2010-05-03</value>
<value>USA</value>
</row>
<row>
<value>26624</value>
<value>0003</value>
<value>2010-05-03</value>
<value>USA</value>
</row>
<row>
<value>26625</value>
<value>0001</value>
<value>2010-05-03</value>
<value>USA</value>
</row>
</data>
</dataset>'
BEGIN
INSERT INTO invoices (invoice, invoice_line, ship_date, country)
SELECT invoice, invoice_line, to_date(ship_date, 'YYYY-MM-DD'), country
FROM XMLTable(
XMLNamespaces(default 'http://developer.cognos.com/schemas/xmldata/1/'),
'/dataset/data/row'
passing xmldoc
columns
invoice varchar2(20) path 'value[1]',
invoice_line number path 'value[2]',
ship_date varchar2(10) path 'value[3]',
country varchar2(100) path 'value[4]'
END;
/If your XML document resides outside the database, you may also access it directly through a DIRECTORY object :
CREATE OR REPLACE DIRECTORY xmldir AS 'C:\oracle\invoices\xml';
INSERT INTO invoices (invoice, invoice_line, ship_date, country)
SELECT invoice, invoice_line, to_date(ship_date, 'YYYY-MM-DD'), country
FROM XMLTable(
XMLNamespaces(default 'http://developer.cognos.com/schemas/xmldata/1/'),
'/dataset/data/row'
passing xmltype( bfilename('XMLDIR', 'invoices.xml'), nls_charset_id('AL32UTF8') )
columns
invoice varchar2(20) path 'value[1]',
invoice_line number path 'value[2]',
ship_date varchar2(10) path 'value[3]',
country varchar2(100) path 'value[4]'
);Some docs about XMLTable and XML querying with Oracle :
http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/functions228.htm#CIHGGHFB
http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14259/xdb_xquery.htm#ADXDB1700
Edited by: odie_63 on 24 juin 2010 20:07 -
Error trying to insert xml into Oracle table
Hi -
I am trying to (a)read a row from emp table and output the results in xml format
and (b) insert this row to another emp_new table (same structure as emp).
When I run it here is what I get:
OUTPUT IS:
<?xml verions='1.0'?>
<Employee>
<Emp num="1">
<EMPNO>7369</EMPNO>
<ENAME>Smith</ENAME>
<JOB>Clerk</JOB>
<MGR>7902</MGR>
<HIREDATE>12/7/1980</HIREDATE>
<SAL>800</SAL>
<DEPTNO>20</DEPTNO>
</Emp>
</Employee>
Exception in thread "main" oracle.xml.sql.OracleXMLSQLException:
No rows to modify -- the row enclosing tag is missing. Specify
the correct row enclosing tag.
etc...
The row enclosing tag is given by setRowTag("Emp").
What's wrong here? Any ideas?
PS: To Ambrose Padilla: Your response was helpful. Thank you.
Program
import java.sql.*;
import oracle.xml.sql.query.*;
import oracle.jdbc.driver.*;
import oracle.xml.sql.dml.*;
class testXML
public static void main(String[] args) throws SQLException
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
//initialize a JDBC connection
Connecton conn = DriverManager.getConnection("jdbc:oracle:thin:mytest:1521:acme", "scott", "tiger");
//initialize the OracleXMLQuery
OracleXMLQuery qry =
new OracleXMLQuery(conn,"select * from emp where rownum < 2");
// set the document name
qry.setRowsetTag("Employee");
// set the row element name
qry.setRowTag("Emp");
// get the XML result
String xmlString = qry.getXMLString();
// print result
System.out.println(" OUPUT IS:\n"+xmlString);
OracleXMLSave sav = new OracleXMLSave(conn,"emp_new");
sav.insertXML(xmlString);
sav.close();
}Try inserting
sav.setRowTag("emp");
before calling insertXML. -
Automotic / Translate XML into create table
Hi, I have a problem with Oracle8i. I like know how translate (automatic or not) the XML or DTD or Schema in databases, how is the correct method.
Hi have a XML documents.
For example:
<?xml version ="1.0">
<Course>
<Name>JAVA WITH XML</Name>
<Teacher>
<Name>David Cabanillas</Name>
</Teacher>
<Students>
<Name>Bo Derek</Name>
<Name>Samantha Fox</Name>
<Name>Sabrina</Name>
</Students>
</Course>
Wich is the representation in "mode" create table?
Thanks.Clob is a good solution if you document is very easy, but I would for example query the exercise with a level = basic and other kind of querys. Clob is a good solution?.
My xml is the next:
<?xml version="1.0" encoding="ISO-8859-1"?>
<exercise title="Mesures de centralitzacis i de dispersis" context="econrmic" format="sections" difficulty="medium" level="basic" time=" ">
<linkedElem name="mitjana aritmhtica" rType="pre" eType="concepte"/>
<linkedElem name="mediana" rType="pre" eType="concepte"/>
<linkedElem name="desviacis tmpica" rType="pre" eType="concepte"/>
<linkedElem name="vari`ncia" rType="pre" eType="concepte"/>
<linkedElem name="coeficient de variacis" rType="pre" eType="concepte"/>
<linkedElem name="quartils" rType="pre" eType="concepte"/>
<tool name="Internet, excel"/>
<statement format="text"><![CDATA[<FONT FACE="Arial" SIZE=2><P ALIGN="JUSTIFY"></P>
<P ALIGN="JUSTIFY">A la pàgina WEB de l_Institut d_Estadística de Catalunya (www.idescat.es) hi trobareu la "Consulta interactiva d_estadístiques" a on accedir a diversos indicadors socials. Cal que captureu la informació corresponent a la Renda Familiar Disponible per habitant corresponent a l_any 1995 per a les comarques de Catalunya.</P>
</FONT><FONT FACE="Arial" SIZE=2><P ALIGN="JUSTIFY"> </P></FONT>]]></statement>
<question title="apartat a" difficulty="low" level="basic" time=" ">
<statement format=" "><![CDATA[<FONT FACE="Arial" SIZE=2><P ALIGN="JUSTIFY"></P><DIR>
<P ALIGN="JUSTIFY">Calculeu la mitjana, la mediana, la variància, la desviació típica i el coeficient de variació de les dades capturades.</P>
<P ALIGN="JUSTIFY"></P>
<P ALIGN="JUSTIFY"> </P></DIR>
</FONT>]]></statement>
<solution format="text"><![CDATA[<FONT FACE="Arial" SIZE=2><P ALIGN="JUSTIFY"></P>
<P ALIGN="JUSTIFY">Mitjana: 1475,98</P>
<P ALIGN="JUSTIFY">	Mediana: 1456,9	</P>
<P ALIGN="JUSTIFY">Variància: 19900,6</P>
<P ALIGN="JUSTIFY">	Desviació típica: 141,07</P><DIR>
<P ALIGN="JUSTIFY">	Coeficient de variació: 9,56</P>
<P ALIGN="JUSTIFY"></P></DIR>
</FONT>]]></solution>
<resolution format=" "><![CDATA[<FONT FACE="Arial" SIZE=2><P ALIGN="JUSTIFY"></P>
</FONT><FONT FACE="Rockwell" SIZE=2><P ALIGN="JUSTIFY"><IMG SRC="Image17.gif" WIDTH=563 HEIGHT=722></P></FONT>]]></resolution>
</question>
<question title="apartat b" difficulty="low" level="basic" time=" ">
<statement format="text"><![CDATA[<FONT FACE="Arial" SIZE=2><P ALIGN="JUSTIFY"></P><DIR>
</FONT><FONT SIZE=2><P ALIGN="JUSTIFY">Agrupeu les dades en els següents intervals: 1200-1300, 1300-1400, 1400-1500, 1500-1600, 1600-1700 i 1700-2000.</P>
</FONT><FONT FACE="Arial" SIZE=2><P ALIGN="JUSTIFY"></P>
<P ALIGN="JUSTIFY"> </P></DIR>
</FONT>]]></statement>
<solution format=" "><![CDATA[<FONT FACE="Arial" SIZE=2><P ALIGN="JUSTIFY"></P>
<P ALIGN="CENTER">Renda Familiar disponible per habitant (1995)</P>
<P ALIGN="CENTER">Milers de pessetes</P>
<P ALIGN="JUSTIFY"><IMG SRC="Image18.gif" WIDTH=253 HEIGHT=123></P>
<P ALIGN="JUSTIFY"></P></FONT>]]></solution>
<resolution format="text"><![CDATA[<FONT FACE="Arial" SIZE=2><P ALIGN="JUSTIFY"></P><DIR>
<P ALIGN="JUSTIFY">Mireu la resolució de l'apartat c).</P>
<P ALIGN="JUS TIFY"></P>
<P ALIGN="JUSTIFY"> </P></DIR>
</FONT>]]></resolution>
</question>
<question title="apartat c" difficulty="low" level="basic" time=" ">
<statement format="text"><![CDATA[<FONT FACE="Arial" SIZE=2><P ALIGN="JUSTIFY"></P><DIR>
</FONT><FONT SIZE=2><P ALIGN="JUSTIFY">Calculeu, sobre les dades agrupades, la mitjana, la mediana, la variància i el primer i tercer quartils.</P>
</FONT><FONT FACE="Arial" SIZE=2><P ALIGN="JUSTIFY"></P></DIR>
</FONT>]]></statement>
<solution format="text"><![CDATA[<FONT FACE="Arial" SIZE=2><P ALIGN="JUSTIFY"></P>
<P ALIGN="JUSTIFY">Mitjana: 1486,59</P>
<P ALIGN="JUSTIFY">	Mediana: 1459,38</P>
<P ALIGN="JUSTIFY">	Variància: 22878,05</P>
<P ALIGN="JUSTIFY">	Primer quartil: 1391,67</P>
<P ALIGN="JUSTIFY">	Tercer quartil: 1546,88</P>
<P ALIGN="JUSTIFY"></P></FONT>]]></solution>
<resolution format=" "><![CDATA[<FONT FACE="Arial" SIZE=2><P ALIGN="JUSTIFY"></P>
</FONT><FONT FACE="Rockwell" SIZE=2><P ALIGN="JUSTIFY"><IMG SRC="Image19.gif" WIDTH=566 HEIGHT=438></P>
</FONT><FONT FACE="Arial" SIZE=2><P ALIGN="JUSTIFY"></P></FONT>]]></resolution>
</question>
</exercise>
My question is:
With clob I could query complex.
Thanks.
null -
XML data into Oracle Tables. XML file on Application Server.Oracle Apps R12
Hi All,
My Database version : 11.2.0.2.0
I have an XML file which needs to be loaded into the Database Tables. How ever i do not want to use the XMLTYPE as given below
insert into test1 (
SELECT PrcDate, PmtType, PmtStatus, PmtTypeCount, PmtTypeAmt
FROM XMLTABLE(
'/WFPaymentAck/RejectedDom1ACH'
PASSING XMLTYPE( BFILENAME('ECX_UTL_LOG_DIR_OBJ','wf_test_xml.XML'), NLS_CHARSET_ID('UTF8') )
COLUMNS
PrcDate VARCHAR2(2000) PATH '@PrcDate' ,
PmtType VARCHAR2(2000) PATH '@PmtType' ,
PmtStatus VARCHAR2(100) PATH '@PmtStatus' ,
PmtTypeCount VARCHAR2(100) PATH 'PmtTypeCount' ,
PmtTypeAmt VARCHAR2(100) PATH 'PmtTypeAmt'
Because this way the XML file needs to reside on the DB server.
I am looking into other option of loading the XML file into a CLOB column of a table and reading it from that column.
I did a couple of tests and feel that this way also the XML file has to reside on the Database Server itself. I am not sure if this is correct or if there is any problem with our TEST instance.
++Can anyone let me know if i need to have the XML file on the DB server instead of the Application server to load into a CLOB column of table ??++
++Or++
++Is there any other workaround for me to load XML into Oracle Tables, while having the XML file on Application Server.++
Your immediate help is appreciated. I need to get past this ASAP.
Thanks in Advance.
VJ1) Are you asking me to create a folder on Database directory which points to a folder on the Apps server ?I suggest creating an Oracle directory object (a database object) pointing to a real location (folder) on Application server.
we DONOT want a hand shake between the DB Server and the APPS server.I don't see where the problem is.
I'm not familiar with Apps R12 but there's no doubt the two servers are already communicating, at least App server should be able to access the DB for the whole thing to run.
As I said :
One way or another, the data has to make its way to the database, there's no workaround to that.How do you imagine the data will end up in a database table if it doesn't come to the DB server?
There's no magical method out there, both servers have to communicate at some point.
About client-server approaches (client being here the App server), you can read about accessing the XML DB repository in the XML DB Developer's Guide : http://download.oracle.com/docs/cd/E11882_01/appdev.112/e23094/toc.htm
Other option : SQL*Loader can load a CLOB, or an XMLType column too
Edited by: odie_63 on 19 déc. 2011 20:22
Maybe you are looking for
-
mac book running slow I tried etresoft but not sure how to inturpret the results any help would be so awesome, thank you Problem description: Computer started running very slowly, when I type there is a delay and internet connection is very slow alth
-
Connect macbook to windows network
Trying to connect a workmate's macbook to MS SBSSRV 2008... absolutely no joy...
-
How to blurr a face or street sign
Ide like to video my walking around manhattan and need some help blurring some faces or other sections of the film. my videos are usually about an hour long and I remove lots of parts any tips on the quickest way to do this. I watched some videos but
-
Unable to renew developer license from vs2013
this is what i get whenever i tried to renew my license . though it was working before installing vs2013 update 4 . whats wrong? ive also reset all vs settings and uninstall and installed again but not working.:( can anyone there to help me. binodtam
-
How to start Process chain ?
Experts, In one of my process chan, Attrib. Change Run got failed. rest of the Process chan ran properly. So, if i open that PC, i could see Red line at the Attr. Change run Tab. How would i just execute my change Run Process only from the Process ch