473,786 Members | 2,712 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

need to parse XML file without root elem

Hello,
I need to parse this XML file or XML stream . Is it possible to parse
it with DOM reading each DataContainer one by one.

<DataContaine r>
<name> </name>
<birthDate> </birthDate>
<personnalInfos >
<personnalInfo_ entries> </personnalnfo_en tries>
<personnalInfo_ elem> </personnalnfo_el em>
<personnalInfo_ elem> </personnalnfo_el em>
</personnalInfos>
</DataContainer>
<DataContaine r>
<name> </name>
<birthDate> </birthDate>
<personnalInfos >
<personnalInfo_ entries> </personnalnfo_en tries>
<personnalInfo_ elem> </personnalnfo_el em>
<personnalInfo_ elem> </personnalnfo_el em>
</personnalInfos>
</DataContainer>

Cheers.

Apr 18 '06 #1
7 3729
> I need to parse this XML file or XML stream . Is it possible to parse
it with DOM reading each DataContainer one by one.
No, DOM documents are required to have exactly one root node, not several.
<DataContaine r>
<name> </name>
<birthDate> </birthDate>
<personnalInfos >
<personnalInfo_ entries> </personnalnfo_en tries>
<personnalInfo_ elem> </personnalnfo_el em>
<personnalInfo_ elem> </personnalnfo_el em>
</personnalInfos>
</DataContainer>
<DataContaine r>
<name> </name>
<birthDate> </birthDate>
<personnalInfos >
<personnalInfo_ entries> </personnalnfo_en tries>
<personnalInfo_ elem> </personnalnfo_el em>
<personnalInfo_ elem> </personnalnfo_el em>
</personnalInfos>
</DataContainer>

Apr 18 '06 #2
What is the solution then? I can not have a root elem solution as I can
have a hudge file.

parse with sax? Any idea?
Thx

Apr 18 '06 #3
In article <11************ **********@j33g 2000cwa.googleg roups.com>,
akira <ak*******@yaho o.fr> wrote:
What is the solution then? I can not have a root elem solution as I can
have a hudge file.


You won't be able to read it with an XML parser if you don't put a
root element around it. I'm not sure why the size of the file should
make it harder to add one.

One way to get a root element is to create a short file with an entity
reference pointing to the "real" data.

<!DOCTYPE dummy [
<!ENTITY data SYSTEM "http://wherever-my-data-is">
]>
<dummy>
&data;
</dummy>

--- Richard
Apr 18 '06 #4
akira wrote:
What is the solution then? I can not have a root elem solution as I can
have a hudge file.

parse with sax? Any idea?


Afaik, SAX is more suitable for large documents than DOM. I don't know if it
supports multiple root nodes. With SAX, afaik, it's not possible to modify
or create documents, you can only parse them and then they are static.
You might also have a look at JDOM or DOM4J, though I don't know much about
these. Just to give you some keywords.

I don't yet understand why having one root node instead of several is a
problem with large documents.

If the reason is that you want to split your data across multiple files, you
could still have a single root node in each one, and then use DOM to
assemble them after you have loaded them. Or (which is a bit dirty) you just
concatenate the files as strings, write "<my-root-node>" at the beginning
and "</my-root-node>" at the end and then parse this string using DOM.

Hope this helps.

Regards,

Felix
Apr 18 '06 #5
Felix Engelhardt wrote:
I need to parse this XML file or XML stream . Is it possible to parse
it with DOM reading each DataContainer one by one.


No, DOM documents are required to have exactly one root node, not several.


That's true. Especially because well-formed XML files
are allowed to have one root only.
<DataContaine r>
<name> </name>
<birthDate> </birthDate>
<personnalInfos >
<personnalInfo_ entries> </personnalnfo_en tries>
<personnalInfo_ elem> </personnalnfo_el em>
<personnalInfo_ elem> </personnalnfo_el em>
</personnalInfos>
</DataContainer>
<DataContaine r>
<name> </name>
<birthDate> </birthDate>
<personnalInfos >
<personnalInfo_ entries> </personnalnfo_en tries>
<personnalInfo_ elem> </personnalnfo_el em>
<personnalInfo_ elem> </personnalnfo_el em>
</personnalInfos>
</DataContainer>


The subject of parsing XML data with multiple roots
comes up about once each month. If you are bound to
usual XSL processors or DOM libraries, then there's
no way out for you. If you are free to choose a tool
with a SAX-like processing style, then you might be
lucky. For example, the XMLgawk extension of the GNU
Awk interpreter allows you to parse XML data with
multiple roots:

http://home.vrweb.de/~juergen.kahrs/...wk-interpreter

One of the authors (Andrew Schorr) processes GigaBytes
of such data and stores it in a database.
Apr 18 '06 #6
Thanks a lot

Apr 18 '06 #7
Felix Engelhardt wrote:
No, DOM documents are required to have exactly one root node, not several.


Because a well-formed XML document is required to have exactly one
top-level element, not several. The file you've shown us is not an XML
document, though it may be an XML External Entity.

DOM DocumentFragmen ts can have several top-level elements. But I don't
know of an off-the-shelf parser that will read an External Entity
directly into a DocumentFragmen t.

One solution is to set up a bit of additional code which wraps a
top-level element around the data as it's read in -- for example, set up
a SAXFilter which generates an extra startElement after the
startDocument event and an extra endElement before the endDocument
event. That does require that the rest of your code be aware this dummy
element was introduced, but that's usually straightforward ... or you can
move these trees into a DocumentFragmen t, if you're working with DOMs.

Saving the data back out may be complicated since, like parsers,
serializers may or may not assume they're intended to process
well-formed XML document. Generally, though, they're more forgiving and
you can get away with using the standard serializer; it's just your
responsibility not to write out the dummy wrapper element.

Good luck.

--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
Apr 18 '06 #8

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

Similar topics

3
23959
by: Jonathan Buckland | last post by:
Can someone give me an example how to append data without having to load the complete XML file. Is this possible? Jonathan
3
2540
by: Sarav | last post by:
Hi All, I need to upload an XML file via an client side ActiveX control. I searched the web but everywhere got the samples of using file control alone. How can I upload a file into my web server without using the <input type ="file" ....> control. I need the same for Download also. Without displaying the Save as dialog box. Why I am asking this is I am going to handle this with my Client side ActiveX control.
3
6799
by: kim | last post by:
GOOD morning, I try to open xx.vbs in <href="./xx.vbs"></hef> but it pop up the file download mesage. How can i disabled it? I try another solution like this : set ws = createobject("Wscript.shell") set oexec = ws.exec("<%=server.mapPath(./xx.vbs)%>") But it give error "the path/xx.vbs is not a valid win32 application" May i know why? I think some setting in registry will open the vbs file
4
2825
by: doritrieur | last post by:
How do i read line from an input file, without the /n ? the readline function returns also the /n character at the end. i need to read a line without the training /n is this possible? thanks, Dorit
15
6326
by: MCondon77 | last post by:
This is probably a common problem, but as a novice programmer I'm trying to figure out how to write 0x0A to a BIN file without having it automatically write 0x0D. Here's an example of the code: tmp_ifp = fopen("tmp_name.bin", "w"); fprintf(tmp_ifp, "%c", 0x0A); When I open the tmp_name.bin file with a hex editor you notice that both 0x0D and 0x0A are written. I tried using fwrite, but the same thing occurs. Any ideas?
18
25729
by: John Bailo | last post by:
I want to write an Excel file (.xls format) from some database data. I don't want to use Excel.exe because of all the automation and security issues. Does Microsoft document the .xls file format anywhere? Is there any c# class that will let me do this?
2
1624
by: solargovind | last post by:
Hi, Can anybody suggest me how to take data from an Excel file without import into Access as a Table..? Bcoz...I hve several file. if i import, it would take more time and increase the file size.. My purpose can explain by below example.. In a Excel file, Assume that Name,Std,Mark1,Mark2,Mark3,etc., are coloumn header, and under this coloumns header, necessary data are filled.
2
1604
by: vishalgupta | last post by:
i need to read/write to a text/binary file without using any header file in c. i cant use the FILE strucutire as it is defined in stdio.h nor can i use file input/output functions as they are defined in fstream.header file???i think that i need to define my own functions for file i/o...how??
11
3895
by: MC | last post by:
I have a couple of customers who are using a program that deserializes an XML file, and on some files, the program fails to see the content of the file -- treats it as zero length and reports "root element is missing" -- even though in Notepad the file looks normal. Has anybody ever seen this? Any clues? I have not been able to reproduce it on my computer. In general, when they e-mail me the files, the files arrive perfectly normal. ...
0
9655
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9497
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10169
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10110
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6749
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5398
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5534
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4067
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
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.