Title: Message
I am creating a linked list when parsing through a DOM document and having a small problem.  When the node is an element node, I check to see if there are more children or siblings and then handle the linked list accordingly.  The problem is that it seems that every node is treated as a sibling, so a dummy sibling node is created after each node.  When an actual child is found, it is placed under the dummy sibling node instead of the actual node.  For example, I get the following when reading an XML file that has a node called 'model' and a child  called 'scale':
 
Name:  model
Value:
Name:  *
Value: *
   Name:  scale
   Value: 0.025
 
This shows the dummy sibling (marked with the *) and the scale child node added under the dummy node vice the 'model' node.  The * in the name and value is just what is put into those fields when the new linked list node is created and is not added from the XML file.
 
Any ideas on what I am doing wrong?  I have included the code snippet below.
 
Thanks.
 
Ken
 
part of a buildList function:
 
case DOM_Node::ELEMENT_NODE :
{
    strcpy(currentPtr->elementName, nodeName.transcode());
 
    // Output any attributes on this element
    DOM_NamedNodeMap attributes = toWrite.getAttributes();
    int attrCount = attributes.getLength();
    for (int i = 0; i < attrCount; i++)
    {
        DOM_Node  attribute = attributes.item(i);
    }
   
   DOM_Node child = toWrite.getFirstChild();
   if (child != 0)
   {
       while( child != 0)
       {
           DOMString tmpName  = child.getNodeName();
           if(child.getNodeType() != DOM_Node::TEXT_NODE) {
               addChildToNode(currentPtr);
               buildList(child, currentPtr->child);
           }
           else {
               buildList(child, currentPtr);
           }
 
          child = child.getNextSibling();
          if(child != 0) {
              DOMString tmpName  = child.getNodeName();
              if(strcmp(tmpName.transcode(), "#text") != 0) {
                  addSiblingToNode(currentPtr);
                  currentPtr = currentPtr->rSibling;
              }
                  
           }
       }
    
     }
    break;
  }

Reply via email to