473,569 Members | 2,789 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to parse a incomplete xml file

11 New Member
I have to write a program where we get the xml file incrementally. i.e the file is constantly updated in the form of xml feed. Thus the first chunk will not be a well formed xml document. However i need to parse the feeds regularly and display the parsed result.

How can this be achieved.?

Eg...

xml field can be following

First chunk is as follows: We can see it is not well formed
Expand|Select|Wrap|Line Numbers
  1. <xml> 
  2. <results> 
  3. <result1> 
  4. </result1? 
  5. <result2> 
  6. </result2> 
The next chunk will be

Expand|Select|Wrap|Line Numbers
  1. <result3> 
  2. </result3> 
  3. <result4> 
  4. </result4> 
  5. </results> 
  6. </xml> 
Please help!! I would be greatful if you could provide me with sample code or some links which i can follow.

TIA
Jan 13 '09 #1
11 8346
Dormilich
8,658 Recognized Expert Moderator Expert
any reasonable xml parser will throw an error if the document is not well-formed. however, there are ways to extend an xml file with additional data (I'm speaking of DOM) without ever using invalid xml, although that depends on the structure of the chunks.

I recommend changing the update process, since xml processing will be much easier on well formed xml.

if there is absolutely no other way, you can try to parse the file tag-wise (like the PHP xml_parse() function).

regards
Jan 13 '09 #2
praveenss
11 New Member
@Dormilich

Hi Dormilich,

The problem is the xml feed is retrieved from the server and is constantly updated on the user screen. So i have to parse the given feed and then update the user screen as and when the xml feed is got.

Can you provide me with the sample code to do the same?
Jan 13 '09 #3
Dormilich
8,658 Recognized Expert Moderator Expert
if you get a feed from a server, it is mostly well-formed. in which way is the feed processed to show up on screen?
Jan 13 '09 #4
praveenss
11 New Member
@Dormilich
Hi,
A well formed xml document is got in chunks and when we get all the chunks we get a well formed xml document. But it can happen that we get a chunk and there will be a delay before we get another chunk of data. But the initial chunk received has to be parsed. Currently for parsing a well formed xml body i am using libxml2.
Jan 13 '09 #5
Dormilich
8,658 Recognized Expert Moderator Expert
@praveenss
do you have to parse the chunk immediately? otherwise I'd wait until the document is complete.

@praveenss
If you must parse the chunk, consider sending chunks that are well formed. although it will result in more program code when it comes to putting the document together...
Jan 13 '09 #6
praveenss
11 New Member
@Dormilich


Yes exaxtly. I have to parse the chunk immediately. As i mentioned the entire document is got as follows

First chunk is:
Expand|Select|Wrap|Line Numbers
  1. <result>
  2. <result1> .... </result1>
  3. <result2>...... </result2>
Next chunk is :
Expand|Select|Wrap|Line Numbers
  1. <result3>....</result3>
  2. <result4> .... </result4>
Finally the feed is terminated

Expand|Select|Wrap|Line Numbers
  1. </result>

If we concatenate the chunks then we get a well formed xml. But the problem arises that we get the xml in chunks and with different delays.
Jan 13 '09 #7
Dormilich
8,658 Recognized Expert Moderator Expert
@praveenss
then there will be no other option than to parse it peace-by-piece. that is, treating the chunks as string and applying string functions to get the data you need.

I still recommend sending the chunks as well-formed xml (unless that's impossible).
Jan 13 '09 #8
jkmyoung
2,057 Recognized Expert Top Contributor
You should be able to use an event driven XML parser, (eg SAX). If you treat the incoming data as a stream as opposed to one file it might be possible to do. The trick would be dealing with the EOF token, ignoring it so that the parser does not throw an error. Then you'd have to route the new input into the stream as it comes.
Jan 13 '09 #9
praveenss
11 New Member
@jkmyoung

Can you please tell me how can we route the new input to the stream. The SAX parser xmlSAXUserParse Memory API can be called for every chunk. But the final output is the parsed content for the complete feed.

The requirement is that i need to refresh the UI with the parsed content of every chunk as and when it arrives.
It would be of great help if you provide some sample code or some link to follow.
TIA
Jan 14 '09 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

10
590
by: Stuart Rogers | last post by:
I have just setup my website with a new linux hosting service. I have copied over my scripts and the jpgraph (the stable version) files from my working local lan linux server. The hosting service runs PHP 4.3.9 and I keep getting parse errors like this- Parse error: parse error, unexpected '=' in...
7
2583
by: Nova's Taylor | last post by:
Hi folks, I am a newbie to Python and am hoping that someone can get me started on a log parser that I am trying to write. The log is an ASCII file that contains a process identifier (PID), username, date, and time field like this: 1234 williamstim 01AUG03 7:44:31 2348 williamstim 02AUG03 14:11:20
4
2952
by: oliver.lin | last post by:
In my simple test code, I tried to define my constructor outside of the class declaration headr file. The header file: file_handler.h ============================================================ 1 #include <string> 2 using namespace std; 3 class file_handler 4 { //Declare member variables 5 private: 6 string file_rd, file_wr; ...
2
4966
by: Vittal | last post by:
Hello All, I am trying to compile my application on Red Hat Linux 8 against gcc 3.2.2. Very first file in application is failing to compile. I tried compiling my application on Linux 7.2 against gcc 3.1 and it got build without any problems. However on against gcc 3.2.2 I hitting this error:
2
2808
by: Mauricio Correa | last post by:
Hello, i try to consume a java web service from a asp .net page, i make without problems the web reference tu wsdl file http://machine/WebService/nameWebService?WSDL in the asp .net page put the code Dim WSConection As New WebService.nameWebService Dim XML_= WSConection .getCcompleteSis(TextBox1.Text) 'this return a string with a XML
2
1867
by: Jan | last post by:
In a 2-page order form, not all applicants will complete it due to field validations. If I want to see data from incomplete orders, can this be done using some sort of session control so that each form page data saved (each press on submit will save data to disk) will have a session number attached to it? Thus if the order log contains...
10
3186
by: Michael B. Trausch | last post by:
Alright... I am attempting to find a way to parse ANSI text from a telnet application. However, I am experiencing a bit of trouble. What I want to do is have all ANSI sequences _removed_ from the output, save for those that manage color codes or text presentation (in short, the ones that are ESChttp://fd0man.theunixplace.com/Tmud.tar which...
29
2881
by: gs | last post by:
let say I have to deal with various date format and I am give format string from one of the following dd/mm/yyyy mm/dd/yyyy dd/mmm/yyyy mmm/dd/yyyy dd/mm/yy mm/dd/yy dd/mmm/yy mmm/dd/yy
50
4436
by: Juha Nieminen | last post by:
I asked a long time ago in this group how to make a smart pointer which works with incomplete types. I got this answer (only relevant parts included): //------------------------------------------------------------------ template<typename Data_t> class SmartPointer { Data_t* data; void(*deleterFunc)(Data_t*);
5
2382
by: praveenss | last post by:
I have to write a program where we get the xml file incrementally. i.e the file is constantly updated in the form of xml feed. Thus the first chunk will not be a well formed xml document. However i need to parse the feeds regularly and display the parsed result. How can this be achieved.? Eg... xml field can be following First...
0
7612
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7924
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8120
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6283
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5219
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3640
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1212
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.