Andrew Patterson wrote:
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 doubt they evaporated. Are you sure you installed a DOMErrorHandler
instance in the DOMBuilder instance? If you did, then you would have seen
an error, since what you describe is not a well-formed XML document,
although it is a well-formed external general parsed entity:
http://www.w3.org/TR/REC-xml/#wf-entities
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?
You are using the canonical method to turn an external general parsed
entity into a well-formed document -- wrapping it in a root element:
http://www.w3.org/TR/xslt#section-XML-Output-Method
Dave
..............................
Andrew Patterson
Software Engineer
Avenza Systems Inc.
email: [EMAIL PROTECTED]
phone: 416.487.5116