Uploaded image for project: 'Axiom'
  1. Axiom
  2. AXIOM-508

Calling OMElement.cloneOMElement after OMElement.toString causes exception

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • 1.3.0
    • 1.4.0
    • Core Model
    • None

    Description

      If there is a descendant processing instruction within an element and the processing has any "psuedo" attributes then calling OMElement.cloneOMElement after OMElement.toString will cause an UnsupportedOperationException exeption.  Example code:

       
              String inputFile = "test-resources\\XMLStaxUtils
      ComplexPITest.xml";        OMDocument inputDoc = XMLStaxUtils.readDocument(inputFile);
              OMElement rootElement = inputDoc.getOMDocumentElement();
              
              // This is the call that causes PIs to get trashed and will cause an UnsupportedOperationException to be thrown when cloning.
              rootElement.toString();
              
              try
              

      {             rootElement.cloneOMElement();             fail("UnsupportedOperationException should have been thrown.  If it was not then axiom has been fixed so update this test and XMLStaxUtils.cloneOMElement.");         }

              catch (UnsupportedOperationException ex)
              

      {         }

      We got around it by creating a helper method that resets the text:
       
              List<OMNode> piNodes = getNodesWithDescendantPI(srcElement);
              for (OMNode piNode : piNodes)
              

      {             OMProcessingInstruction pi = (OMProcessingInstruction) piNode;             String piValue = pi.getValue();             pi.setValue(piValue);         }

              return srcElement.cloneOMElement();
       

      Attachments

        1. ComplexPITest.xml
          102 kB
          Kyla Miller

        Activity

          People

            veithen Andreas Veithen
            kylabohon Kyla Miller
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: