2 Replies Latest reply on Mar 5, 2009 11:09 AM by tfennelly

    Smooks & Groovy mask illegal attribute names

    ama1

      Hi Forum,
      I try to rename a xml-element with groovy and smooks:

      <g:groovy executeOnElement="csv-record">
       <g:script>
       <!--
       //Rename the target fragment element from "csv-record" to "address"...
       DomUtils.renameElement(element, "address", true, true);
       -->
       </g:script>
      </g:groovy>
      


      Problem is that the generated groovy class uses the element-name 'csv-record' as part of an attribute name:
       public void visitAfter(Element element, ExecutionContext executionContext, Writer writer) {
       Element csv-record_Mangled = element;
       Document document = element.getOwnerDocument();
       Map nodeModels = DOMModel.getModel(executionContext).getModels();
      
       def writeFragment = { outNode ->
       if(outNode.getNodeType() == Node.ELEMENT_NODE) {
       Serializer.recursiveDOMWrite((Element) outNode, writer);
       } else if(outNode.getNodeType() == Node.DOCUMENT_NODE) {
       Serializer.recursiveDOMWrite(outNode.getDocumentElement(), writer);
       } else {
       throw new SmooksException("Call to 'writeFragment' with a non Document/Element Node. Node type: " + outNode.getClass().getName());
       }
       }
      
      
      
       //Rename the target fragment element from "csv-record" to "address"...
       DomUtils.renameElement(element, "address", true, true);
      
      
       }
      


      Strange is that this attribute is never used. But anyway, is there a way to mask this name??