Uploaded image for project: 'Xerces2-J'
  1. Xerces2-J
  2. XERCESJ-1407

renameNode creates wrong Node Implementation with PSVI, HTML and WML DOM

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 2.9.1
    • 2.10.0
    • DOM (Level 3 Core)
    • None

    Description

      I stumbled across an issue when using the DOM Level 3 renameNode method but this issue is actually more than only related to renameNode:

      Depending on parameters the DOM Level 3 renameNode method analyses whether renaming a node would cause a change of node implementation type, i.e. whether an instance of ElementImpl or AttributeImpl will be renamed such that it aquires a Namespace and thus needs to be converted to their respective NS counterparts (ElementNSImpl, AttrNSImpl).

      Depending on the ourcome of this, there are two issues:

      Issue 1:
      If the to-be-renamed node not an NS aware type (i.e. ElementImpl or AttrImpl) and a namespace shall be set, xerces instantiates a new ElementNSImpl/AttNSImpl by calling the class constructor for these hardcoded.
      However, when using the PSVI-aware DOM, this is the wrong class type! It should be PSVIElementNSImpl instead!

      Xerces should call document.createElement instead so the correct class will be instanciated.

      Actually I think it is a general problem that xerces sometimes call node constructors hard coded instead of using the document.create methods and suggest changing this.

      Issue 2:
      If the to-be-renamed node is of an NS-implementation-type or the namespace is null, an internal rename method will be called upon the element/attribute implementation and the same node object will be returned.
      This is fine for the standard implementation, however in sometimes wrong for the HTML and WML DOM.
      The HTML and WML-DOM use specific element implementation classes i.e. HTMLHeadingElementImpl or HTMLParagraphElementImpl.
      In these cases, instead of calling the internal rename method, the element should be re-created using the createElement method of it's document implementation.

      The solution here is the same as for issue 1:
      use the document.create methods for renaming an element.
      However we need to query whether the used DOM implementation allows element instances to be renamed (general XML) or not (HTML, WML).

      Please find attached a patch that:

      1) replaces every call to Node imlementation constructors (except instances of DocumentImpls) by calling the respective document.create method
      2) queries whether a DOM implementation permits node renaming and if not, re-created elements upon calling rename.
      I attached a patch that fixes these two issues.
      I'd be pleased if someone could review whether the proposed solution is ok.

      Attachments

        1. RenameNodePatch.txt
          13 kB
          Ludger Bünger

        Activity

          People

            mrglavas@ca.ibm.com Michael Glavassevich
            ludger.buenger Ludger Bünger
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: