Page 1 of 2

XML Parsing

Posted: Wed Nov 19, 2008 2:55 pm
by krishna81
Hi,

i need to extract the file contains data in XML format and output should fletten.please see below the input format:

File name:File1.txt

<?xml version="1.0" encoding="UTF-8"?>
<message:Message xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:message="http://message.xyz.xyz.xyz.com" xsi:type="this is message2">
<key>
<messageId>11111AAAAA</messageId>
</key>
<partitionKeyNumber>22</partitionKeyNumber>
<source>
<IdCD>AAA</IdCD>
<Code>111</Code>
<LocationCode>BBB</LocationCode>
</source>
</message:Message>
<?xml version="1.0" encoding="UTF-8"?>
<message:Message xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:message="http://message.xyz.xyz.xyz.com" xsi:type="this is message2">
<key>
<messageId>22222BBBBB</messageId>
</key>
<partitionKeyNumber>22</partitionKeyNumber>
<source>
<IdCD>ABC</IdCD>
<Code>222</Code>
<LocationCode>DEF</LocationCode>
</source>
</message:Message>

expected output :

message Messageid partitionKeyNumber IdCD Code LocationCode
---------------------------------------------------------------------------------
this is message1 11111AAAAA 22 AAA 111 BBB
this is message2 22222BBBBB 22 ABC 222 DEF

please suggest in this.
i appreciate for your response.

Kris

Posted: Wed Nov 19, 2008 3:02 pm
by chulett
What have you tried, anything? Do you have an xsd for this and have you imported the metadata to create the XPath Expressions?

Posted: Wed Nov 19, 2008 3:59 pm
by krishna81
when i tried to open in xml file it is issuing error

"Only one top level element is allowed in an XML document. Error processing resource"

Actually it is .txt file,when i tried by converting .txt to .xml in windows and import metadata it is not allowing.

my quick question is how can we extract xml data if it contains more than one elements like
<?xml version="1.0" encoding="UTF-8"?>
<message:Message xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:message="http://message.xyz.xyz.xyz.com" xsi:type="this is message2">
.
.
.
.
.
<?xml version="1.0" encoding="UTF-8"?>
<message:Message xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:message="http://message.xyz.xyz.xyz.com" xsi:type="this is message2">
.
.
.
.
.


Regards
kris

Posted: Wed Nov 19, 2008 4:02 pm
by chulett
krishna81 wrote:"Only one top level element is allowed in an XML document. Error processing resource"
Your answer is right there... nope.

And the extension doesn't matter, txt v. xml, what matters is the content.

Posted: Wed Nov 19, 2008 4:05 pm
by krishna81
the content is in xml format .

Posted: Wed Nov 19, 2008 4:12 pm
by chulett
Right, we can see that, which means there should be no reason to "convert it to XML in Windows".

Posted: Wed Nov 19, 2008 4:24 pm
by krishna81
when i am trying to import the metadata the it is throwing following error.

"Line 13,Position 3:The XML declaration is Unexpected. Line 13,Position 3."

Posted: Wed Nov 19, 2008 4:32 pm
by chulett
What are you importing from? An xsd or the xml file itself? Best to get an xsd if at all possible.

Posted: Wed Nov 19, 2008 4:48 pm
by krishna81
I did not see any XSD option in import tab.

I renamed File1.txt to File1.xsd and tried to import using XML Table definitions...

it is throwing following error:


Line 2,Position2:Expected Schema root.Make sure that the root element is <schema> and the namespace is 'htt//www.w3.org/2001/XMLSchema' for an XSD schema or 'urn:schemas-microsoft-com-data'for an XDR schema.An error occured at file:///C:/document

Posted: Wed Nov 19, 2008 4:57 pm
by chulett
1) Sure there is. When you go to "Open" the file in the XML Meta Data Importer tool, there is a prompt for "Files of type". Both "XML schemas and documents" and "XSD files" will work, as well as the ever popular "All files". Unless it has totally changed for 8.x, that is, but there still must be a way to import from them.

2) You cannot simply rename the file like that. An xsd file is completely different from an XML file. Request the matching xsd from whomever is providing you with the xml.

Posted: Wed Nov 19, 2008 5:04 pm
by krishna81
Actually file is coming with .txt but contents are in XML format.

Posted: Wed Nov 19, 2008 5:52 pm
by chulett
Yes, we know. And? :?

Posted: Thu Nov 20, 2008 10:03 am
by eostic
You need to break it up.... you don't have one xml document in your text file ---- you have MANY xml documents in your text file. Each one can be read independently. You will have to break them up........ or get the person/app sending them to you to break them up as individual .txt files, individual messages, individual rows, etc.

Still, using DS to break it up is possible...think of this as just a set of longvarchars that each are delimited by <? xml .....once you have each set of <? xml..... in its own column you'll be able to do what you need.

To import the metadata, just cut/paste one of them into its own xml document and import, but be careful --- the concerns above for having an xsd are valid --- you'll need one if the instances that you have are not complete with all elements and attributes.

Ernie

Posted: Thu Nov 20, 2008 10:07 am
by eostic
poor choice of words above....get each xml section into its own "row". Lots of techniques for doing that.

Ernie

Posted: Thu Nov 20, 2008 10:22 am
by kittu.raja
[quote="eostic"]You need to break it up.... you don't have one xml document in your text file ---- you have MANY xml documents in your text file. Each one can be read independently. You will have to break them up

If we try to split the data with delimiter "<xml", if we dont know how many messages we have then how many columns we have define in the delimited file?