Home » Developer & Programmer » JDeveloper, Java & XML » List all Tag and Field Names in XML (Oracle 11g)
List all Tag and Field Names in XML [message #654698] |
Wed, 10 August 2016 10:33  |
lokimisc
Messages: 101 Registered: February 2008
|
Senior Member |
|
|
Hi,
I'm working on a program which reads xml files and list all tags and their corresponding child fields which will be used to compare against the table and columns created in database.
Could anyone please help in listing tags and field names from xml file.
Input XML File:
<ordering>
<order>
<orderNumber>316</orderNumber>
<OrderName>MOBILE</OrderName>
<BusinessType>COMMERCIAL</BusinessType>
<OrderStatus>PENDING</OrderStatus>
<shipto>
<name>Ola Nordmann</name>
<address>Langgt 23</address>
<city>4000 Stavanger</city>
<country>Norway</country>
</shipto>
<item>
<title>Empire Burlesque</title>
<note>Special Edition</note>
<quantity>1</quantity>
<price>10.90</price>
</item>
</order>
<ordering>
Output ( It can be inserted into table, if required )
TagName FieldName
ordering NULL
order orderNumber
order OrderName
order BusinessType
order OrderStatus
shipto name
shipto address
shipto city
shipto country
item title
item note
item quantity
item price
Thanks and Regards,
Lokesh
|
|
|
|
|
Re: List all Tag and Field Names in XML [message #654701 is a reply to message #654699] |
Wed, 10 August 2016 13:32   |
lokimisc
Messages: 101 Registered: February 2008
|
Senior Member |
|
|
Thanks Bill for your response.
We receive xml file using which data has to be loaded into database but issue is frequently there is addition and deletion of tags and fields in xml file. So Im trying to validate file before processing.
Please let me know, if you have any questions.
Regards,
Lokesh
|
|
|
|
|
|
|
|
|
|
Re: List all Tag and Field Names in XML [message #654710 is a reply to message #654709] |
Wed, 10 August 2016 23:51   |
lokimisc
Messages: 101 Registered: February 2008
|
Senior Member |
|
|
Thanks Barbara Boehmer for the solution.
But when I execute the query it is returning null values in parent_name while listed all tag names in child_name column.
I copied xml data from your post and created xml file, Please let me know if I'm missing anything.
Regards,
Lokesh
|
|
|
|
Re: List all Tag and Field Names in XML [message #654760 is a reply to message #654710] |
Thu, 11 August 2016 15:45   |
 |
Barbara Boehmer
Messages: 9105 Registered: November 2002 Location: California, USA
|
Senior Member |
|
|
lokimisc wrote on Wed, 10 August 2016 21:51Thanks Barbara Boehmer for the solution.
But when I execute the query it is returning null values in parent_name while listed all tag names in child_name column.
I copied xml data from your post and created xml file, Please let me know if I'm missing anything.
Regards,
Lokesh
You must have done something different. It is difficult to guess what that might be. You mentioned parent_name and child_name, which I did not use. I used parent_tag and child_tag, so obviously you changed those and I have to assume that you changed other things. When attempting to adapt an example, it is best to run it exactly as is, then try to make one minor modification at a time, testing between each modification, so that when something fails, you know which modification caused it. If you were to copy and paste the run of the query from SQL*Plus with line numbers and results, as I did, then it should be obvious what is different.
Since you got some results, the xml file must have been readable, so it must have been valid xml and you must have had a proper directory object, so the query must have been different. Perhaps you did not copy and paste that exactly. I will provide it again below, without line numbers, so that you can copy and paste it. If that does not solve your problem, then you need to post the run of the query from SQL*Plus, as I did, so that we can see what is different. If you are using a different directory than XML_FILES, then go ahead and change that, making sure it is in upper case, but please do not try to change anything else. All it takes is changing one little thing like / or * or . or ( or ) or a column name or upper or lower case to have something fail in such a query. If you do get it to work by copying and pasting, but have something else that does not return the same results, then you can post both and we should be able to see what is different and explain why it causes different results.
SELECT *
FROM XMLTABLE
('//*'
PASSING XMLTYPE (BFILENAME ('XML_FILES', 'INPUT_FILE.XML'), NLS_CHARSET_ID ('AL32UTF8'))
COLUMNS
parent_tag VARCHAR2(30) PATH '../name(.)',
child_tag VARCHAR2(30) PATH 'name(.)')
/
|
|
|
|
Goto Forum:
Current Time: Sat May 24 05:47:28 CDT 2025
|