Skip to main content
GameDev.net gamedev.net
🔒 Locked

Using XML DOM

Started by Darkor Oct 29, 2004 at 11:23 AM 3 replies 1.3k views
Original Post
Darkor
Darkor
I store quite a bit of information in XML files and was wondering if using DOM to read them all in was a good idea. Firstly, I'm going to edit these data, so most online articles suggest using DOM. However, I wish to implement search functionality and was thinking along the lines of using a forward parser to read in all the data and store them in a SortedList. These will require my XML data to be indexed and will this be a good idea? I will only use DOM, to edit fragments of XML data, which I read in using the index. I believe XPath will be used for this purpose. Am I on the right track?
chollida
chollida
If you want to search through your xml, using a DOM is sometimes the only way, short of parsing all the xml into yoru own containers.

I'm almost certain that XPath requires DOM as SAX only has knowledge of hte current XML fragment, and not the entire Doc.

As an aside, MSXML is a great xml parser.

We tend to use a hybrid of DOM and SAX where we load a doc using SAX and save out large data chunks, to disk and replace them with tokens. After this preparsing stage we load the doc using the DOM and then we can use simple XPath Queries to find what ever your looking for.

Cheers
Chris
Darkor
Darkor
Is parsing the xml data into my own containers advisable?

In your hybrid approach, you say you use SAX to save large chunks of data to disk. I don't get why you're doing this and what do you mean by replacing them with tokens?

I'm guessing that by tokens, you mean something like a unique ID. Presumably, you generate these tokens by yourself. But how are you going to use these tokens to represent data in the XML database? Using the index of the elements?

Thanks for the reply.
chollida
chollida
You have the idea.

THe only reason we do the preparse is that sometimes an XML document can become very large and loading it using the DOM is impossible as DOM requires the whole tree to be available.

Say you have a data base of people. Each node is a person. We would preparse the XML using SAX and save each person's data to disk in our own format, what ever that is is implementation specific. We replace that data with a unique token.

You can then load the xml using the DOM, if you need the data you load it based on the token.

XML is big, Base64 encoded data doesn't help things but if you want ot work with the internet you've got to play by the rules:)

Cheers
Chris
Darkor
Darkor
You just said that DOM requires the entire tree to be available so won't that mean that loading the entire XML database using DOM is inevitable?

In that case, the data generated in preparsing will only be used for listings and searches because it's faster?

How are your unique tokens generated? Are they like primary keys from your XML elements or simply autonumbers?

I realise that all my sentences are questions =x

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.