jkesselm    01/07/10 15:23:55

  Modified:    java/src/org/apache/xml/dtm/ref/dom2dtm DOM2DTM.java
  Log:
  Quick patch to handle case where someone wants to build a DTM from
  an Element rather than from a Document. The Attr handling might want to
  move down into addNode.
  
  This opens several cans of worms -- what if the next user wants the
  root of their DTM to be an EntityReference node, which has no DTM
  node equivalent -- but we'll eat those when we get to them.
  
  Revision  Changes    Path
  1.9       +34 -3     xml-xalan/java/src/org/apache/xml/dtm/ref/dom2dtm/DOM2DTM.java
  
  Index: DOM2DTM.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xml/dtm/ref/dom2dtm/DOM2DTM.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- DOM2DTM.java      2001/06/29 16:24:06     1.8
  +++ DOM2DTM.java      2001/07/10 22:23:50     1.9
  @@ -143,12 +143,43 @@
       super(mgr, domSource, dtmIdentity, whiteSpaceFilter, 
             xstringfactory, doIndexing);
   
  -        // Initialize DOM navigation
  +    // Initialize DOM navigation
       m_pos=m_root = domSource.getNode();
  -        // Initialize DTM navigation
  +    // Initialize DTM navigation
       m_last_parent=m_last_kid=NULL;
       m_last_kid=addNode(m_root, 0, m_last_parent,m_last_kid, NULL);
  -        // Initialize DTM-completed status 
  +
  +    // Apparently the domSource root may not actually be the
  +    // Document node. If it's an Element node, we need to immediately
  +    // add its attributes. Adapted from nextNode().
  +    // %REVIEW% Move this logic into addNode and recurse? Cleaner!
  +    //
  +    // (If it's an EntityReference node, we're probably scrod. For now
  +    // I'm just hoping nobody is ever quite that foolish... %REVIEW%)
  +    if(ELEMENT_NODE == m_root.getNodeType())
  +    {
  +      NamedNodeMap attrs=m_root.getAttributes();
  +      int attrsize=(attrs==null) ? 0 : attrs.getLength();
  +      if(attrsize>0)
  +      {
  +     int attrIndex=NULL; // start with no previous sib
  +     for(int i=0;i<attrsize;++i)
  +     {
  +       // No need to force nodetype in this case;
  +       // addNode() will take care of switching it from
  +       // Attr to Namespace if necessary.
  +       attrIndex=addNode(attrs.item(i),1,0,attrIndex,NULL);
  +       m_firstch.setElementAt(DTM.NULL,attrIndex);
  +     }
  +     // Terminate list of attrs, and make sure they aren't
  +     // considered children of the element
  +     m_nextsib.setElementAt(DTM.NULL,attrIndex);
  +
  +     // IMPORTANT: This does NOT change m_last_parent or m_last_kid!
  +      } // if attrs exist
  +    } //if(ELEMENT_NODE)
  +
  +    // Initialize DTM-completed status 
       m_nodesAreProcessed = false;
     }
   
  
  
  

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

Reply via email to