Hi List and Xerces Gods,

First let me say "Hello all!" as i'm new to the list. Second, i haven't
found a xerces-c-user list (as like as the xerces-j-user and
xerces-j-dev ones). So i hope i'm not offtopic with my questions here.
If so please excuse me in advance.

Now to my problem. I develop an application using the Xerces-C under
C/C++. I have to load/parse a XML (let it me call) template. In this
template there are certain positions with my own datamarkers, where i
fill in some data to get a complete filled out XML Document to save. So
i get many documents of the same structure with different datas in. You
got the idea?

I load and parse the template. Then i create a DOMNodeListIterator from
the RootElement of the Document to traverse the nodes sequentially and
do my replacing where neccessary. All works fine so far.

But now i have a little problem. There may be sometimes the neccessity
to duplicate a node with all ist children (subtree). It consists of the
amount of datas supplied. Sometimes i need the whole subtree once,
sometimes i need it 10 times. So i remember the node and ist subtree in
a DOMDocumentFragment for later use in the
"template-form-with-markers-and-no-data-in-it" and the parent of this
node.

If i now have to duplicate the subtree, i insert the DOMDocumentFragment
with appendChild to the remembered parent node. This works also very
fine.

I append some relevant Codesnippets to this mail, so that you can see my
ugly XML-Xerces-Programming-Style and see what i do so far.

Now my questions:

1.
Is a DOMNodeIterator LIVE? So the changes in the document (which affects
the listed node in the Iterator) will be visible to my earlier to the
changes created Iterator? Or have i to release the Iterator and create a
real new one every time i change the underlying document? The
documentation says nothing that a Iterator is live as in other cases
where it is mentioned explicitly.

2. 
If the Iterator is LIVE. Where is the actual node positioned. As i
insert the new subtree when i reach the end of the just processed
subtree and the new one is a sibling to the actual. Will i get the first
node of the new inserted subtree if i call simply nextNode? I miss a
setPosition or whatever function in the iterator. 

3. 
If it is not live or the nextNode-Call will give me uncertain values i
tried to use getRoot on the Iterator and traverse it again with an
isSameNode-Comparison with the remembered last processed node. So i can
recognize my last position and work further from there on. But strange,
i never get an TRUE on the isSameNode-Comparison. The loop loops until
it get NULL (no more nodes). :-(( Don't know why or what i'm doing
wrong. Any hint here?

4. 
Is there a better way to do what i want to do? Traverse a doc, acting on
special nodes and if neccessary doubling nodes and subtrees and process
them also after insertion with datafilling? All "lightbulbs" sent to me
are welcome to do some enlightenment.

Any hint, URL, documentation, file, sample is really appreciated.

TIA
Joerg Toellner

Codesnippets follows:
------------------------------------------------------------
DOMDocument* dom_MergeTemplWithFData(DOMImplementation *impl, char
*templfile,
                                     DOMBuilder *builder, char
*fdatafile, 
                                     void
fdata_CBPostProcess(dom_str_fdata*))
{
    DOMDocument *doc;
    DOMNode *nd, *atnd, *delnd, *tmpnd, *reptparent;
    DOMNodeIterator *dni;
    DOMNamedNodeMap *attrs;
    DOMDocumentFragment *docfrag;
    char tmpbuf[DOM_MAXLEN], reptfeld[DOM_MAXLEN], *pos;
    char atnam[DOM_MAXLEN], atval[DOM_MAXLEN];
    int x, reptanz, aktrept;
    dom_str_fdata *fdata, *akt_fdata;

    // Loading and parsing the doc
    doc = dom_ParseDoc(impl, templfile, builder);
    docfrag = doc->createDocumentFragment();

    ...

    // Taverse doc node by node
    dni = doc->createNodeIterator(doc->getDocumentElement(),
                DOMNodeFilter::SHOW_ELEMENT, NULL, TRUE);
    ...

    // Starting at the first node
    nd = dni->nextNode();
    while(nd != NULL)
    {
      ...

        // Do my Fill-in-Data-Processing here
      // and many other unintersting stuff

      ...

      // Remember the actual node and ist subtree for later use
      docfrag->appendChild(nd->cloneNode(TRUE));

        ...

        // more unimportant stuff

        ...

        // Get the next node if possible
        x++;
        atnd = attrs->item(x);
    }

    // Is a repetition of the nodesubtree neccesary?
    if(reptanz != 0)
    {
        // Yes! Do something
        ...

        // and append the remembered subtree from the documentfragment
        tmpnd = reptparent->appendChild(docfrag);

        // As i dont know if the Iterator is live -> create a new one
for the now changed doc
        // Maybe this can be simplified when the iterator is live
        dni->release();
        dni = doc->createNodeIterator(doc->getDocumentElement(),
                            DOMNodeFilter::SHOW_ELEMENT, NULL, TRUE);
        // Positioning the Iterator to the beginning of the doc
        nd = dni->nextNode();
        // Searching the point where i stopped in the iterator to
continue from this
        // point on again
        while(nd != NULL && !(nd->isSameNode(tmpnd)))
            nd = dni->nextNode();

// HELP HERE PLEASE!
// This don't works so far! The while always runs through all nodes
until the iterator dries
// out of nodes and returns NULL :-((( Why? I dunno why the isSameNode
never evals to TRUE.

        // Continue now with datafilling with this found node as the
actual one
        continue;

        // Versuchen die naechste Node zu bearbeiten
        nd = dni->nextNode();
    }

    ... And more stuff here -> Skipping for this time
    
    // Cleanup and returning the parsed, data-filled-in document 
    dom_DeInitFData(fdata);
    dni->release();
    docfrag->release();
    return doc;
}
------------------------------------------------------------
END


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to