General XMetaL Discussion

XMetaL Community Forum General XMetaL Discussion Xml of cloned node not proper

  • sapraaman

    Xml of cloned node not proper

    Participants 1
    Replies 2
    Last Activity 12 years, 7 months ago


    If we clone a node using .cloneNode(true) method, and call .xml method on it, the xml returned has all the attributes, attribute values and all the text represented as entities. This makes the method quite not of much use. The method could be very helpful to us for debugging purposes.

    var clonedNode = node.cloneNode(true);

    We are using XMetal 5.5



    Derek Read

    Reply to: Xml of cloned node not proper

    We did not envision your usage when .xml was implemented here so this just looks like an oversight to me. I'll have development look into it.

    In the meantime, I think you can use Range.TextWithRM to get what you need. Here is an example that will need to be modified to give you exactly what you want:

    [code]//XMetaL Script Language JScript:
    var rng = ActiveDocument.Range;
    //Create a node based on current selection. If you have already defined a node object
    //called “node” (as in your original script snippet) you won't need this next line.
    var node = rng.ContainerNode;
    //Move the rng to your node. In this example it is the same place,
    //in your case it is probably a different location in the document.

    If you are sure there are no revision marks, or do not want to include them you can use rng.Text instead.

    For help switching between node representations of “where you are” (DOM) and Selection/Range objects see the Programmer's Guide topic “DOM interfaces” and scroll down to where it says “Working with selections and nodes”.



    Reply to: Xml of cloned node not proper

    Thanks Derek for the tip.


  • You must be logged in to reply to this topic.

Lost Your Password?