xerces-c-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrew Patterson <and...@avenza.com>
Subject Re: How to parse an XML string in memory? and get a DOM tree out of it
Date Wed, 13 Sep 2006 19:52:52 GMT
> Sure you can, you just can't use DOMBuilderImpl::parseWithContext().  
> Just use the regular parse() member function:
> 
> DOMDocument* DOMBuilderImpl::parse(const DOMInputSource& source)

Ah, okay, got it working. I tried parse() first and couldn't get it 
working right. That's when I moved on to parseWithContext() (it seemed 
more appropriate for what I was doing). I've figured out what I was 
doing wrong with parse() -- all is good! Many, many thanks!

One last question, purely out of curiosity. I've been dumping unused 
nodes into document fragment and then writing it out to string for 
storage. What I've been trying to do is pull it back out later on (the 
XML parsers may be terminated in the interim which is why I have to save 
it as a string temporarily instead of just leaving the DOM fragments 
intact).

If the document fragment had one node in it, all was fine. Got the first 
child of the parsed string and there it was. But if there was more than 
one node, they seem to evaporate when parsed (Maybe I'm just traveling 
the resultant DOM wrong though). I.e. when I ask the first child for 
it's sibling, I get zero.

I solved this by adding a 'container' element to the fragment first when 
saving, and dumping extra nodes into that -- and, of course, moving down 
an additional level when parsing it back out. Still, it seems like a 
strangely unnecessary step. Is this an unavoidable result of not having 
a root node in my fragment? Or am I just not traversing the parsed out 
document fragment correctly?

..............................
Andrew Patterson
Software Engineer
Avenza Systems Inc.

email: andrew@avenza.com
phone: 416.487.5116

Mime
View raw message