Stephane Mottelet wrote:
> Why is not possible to wrap an existing element in
> a comment ? It is just possible to insert a comment
> before and after.

It is also possible to insert a comment *into* an element.

XXE has many shortcomings. Not being able to wrap an existing element in
a comment is just one of them.

Fortunately, XXE is extensible so you can write such a command yourself.

Just for the fun, I have written a simple version of this command as a 
macro-command (I admit that it was pretty challenging to do that):

---
   <command name="wrapInComment">
     <macro trace="false">
       <sequence>
         <pass><command name="delete" /></pass>

         <set variable="elementPrefix"
              expression="concat('&lt;', local-name($selectedElement))"/>

         <command name="grabSelectedElement" />
         <set variable="elementData" expression="%_" plainString="true"/>

        <command name="insertNode" parameter="commentAfter" />
        <set variable="newComment" expression="$selected" />

        <command name="selectNode" parameter="previousSibling" />
        <command name="delete" />

        <set variable="dot" expression="$newComment" />

        <get expression="concat($elementPrefix,
           substring-after($elementData,$elementPrefix))"/>
         <command name="paste" parameter="into %_" />
       </sequence>
     </macro>
   </command>

   <command name="grabSelectedElement">
     <process showProgress="false">
       <copyDocument selection="true" to="element.xml"
                     indent="true" encoding="UTF-8" />
       <read file="element.xml" encoding="UTF-8" />
     </process>
   </command>
---

To play with this macro, simply save the attached file to 
XXE_user_preferences_dir/config/customize.xxe and restart XXE. 
(XXE_user_preferences_dir is "C:\Document and Setting\xxe2" on Windows.)

Note that:

[1] You need to explicitly select an element before pressing on F6 (I've 
bound the command to function key F6).

[2] The selected element must not contain a comment.

[3] This simple version should work fine with documents conforming to a 
DTD, but needs to be improved for use on multi-namespace documents 
conforming to a W3C schema.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: customize.xxe
Type: text/xml
Size: 1603 bytes
Desc: not available
Url : 
http://www.xmlmind.com/pipermail/xmleditor-support/attachments/20040707/614ad73e/attachment.xml
 

Reply via email to