473,387 Members | 1,517 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Split file that contains multiple XML

Hi,

We have a file that contains multiple XML-Messages in the form of:

<FIRSTMESSAGE>...</FIRSTMESSAGE><SECONDMESSAGE>...</SECONDMESSAGE>

I know this looks broken from the beginning, but we cannot change the
application that generates these kind of data, so we need a way to cope
with it.

How would I go about reading/splitting this? I don't think there is
functionality available to do this with Xerces, right?

I thought about using SAX to try to parse the complete text (we should get
an error at the second message) and then read the char/line information
from the errormessage, but this sounds like a hack to me, is there some
other way?

Thanks... Dominik.
Jul 20 '05 #1
3 1335
Hi,

I have actually done exactly what you suggested using the Expat SAX
parser
(and this feature is now included
in the XML gawk extension found at
http://sourceforge.net/projects/xmlgawk).
The key is to call XML_Parse until it returns XML_STATUS_ERROR.
At that point, one calls XML_GetCurrentByteIndex to find the location
of the error. You can then close out the parsing of the previous
document,
and then start parsing the new one that begins at the returned error
offset into the file. To see how this is done, you can look in
xml_puller.c in the sourceforge repository:

http://cvs.sourceforge.net/viewcvs.p....6&view=markup

Or you can just use xmlgawk and not worry about implementing this
yourself.

Regards,
Andy

Jul 20 '05 #2
In article <pa****************************@thegoldensource.co m>,
Dominik Stadler <ds******@thegoldensource.com> wrote:
We have a file that contains multiple XML-Messages in the form of:

<FIRSTMESSAGE>...</FIRSTMESSAGE><SECONDMESSAGE>...</SECONDMESSAGE> How would I go about reading/splitting this?


Wrap an element around it so it is

<x><FIRSTMESSAGE>...</FIRSTMESSAGE><SECONDMESSAGE>...</SECONDMESSAGE></x>

and then just extract the children of that element.

-- Richard
Jul 20 '05 #3
It seems to me that this method will not work if any of the messages
contain XML declaration
headers. When I try your technique by feeding some concatenated
messages, each of which
contains an XML declaration, into the Expat parser, I get this error
message:

xml declaration not at start of external entity

But I expect your technique should work fine if there are no XML
declarations in the
messages.

Regards,
Andy

Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: kumu | last post by:
How to Split a XML file to multiple small XML Files Hello, I am trying to split a XML file to multiple small xml files in vb.net and am trying to get the best possible approach to this. Any help...
4
by: qwweeeit | last post by:
The standard split() can use only one delimiter. To split a text file into words you need multiple delimiters like blank, punctuation, math signs (+-*/), parenteses and so on. I didn't...
3
by: rxl124 | last post by:
Hi, room Beginner of learning perl here!! I have question to all, I have below file name datebook.master which contains only 2 lines Mike wolf:12/3/44:144 park ave, paramus: 44000 Sarah kim:...
7
by: Warren Wright | last post by:
Hello, We maintain a 175 million record database table for our customer. This is an extract of some data collected for them by a third party vendor, who sends us regular updates to that data...
11
by: pmarisole | last post by:
I am using the following code to split/join values in a multi-select field. It is combining all the values in All the records into one long string in each record in recordset. Example: I have a...
6
by: Vlado Jasovic | last post by:
Hello, We're developing application in VS2005 using vb.net. Our application exe file is ~20mb when compiled. Recently, we have developed auto-update feature that goes on our web-site,...
24
by: garyusenet | last post by:
I'm working on a data file and can't find any common delimmiters in the file to indicate the end of one row of data and the start of the next. Rows are not on individual lines but run accross...
1
by: Query Builder | last post by:
I have one of our production Accounting Databases starting from 2 GB now grown into a 20 GB Database over the period of a few years... I have been getting timeouts when transactions are trying to...
7
by: John Smith | last post by:
Hi, I am very new to C# and NET framework. I am trying to hash (using MD5CryptoServiceProvider) a source that is split into several files. Now when the source is in one file I can produce the...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.