DITA and XMetaL Discussion

XMetaL Community Forum DITA and XMetaL Discussion Using the MoveToElement method to set attribute values

  • bjorn

    Using the MoveToElement method to set attribute values

    Participants 0
    Replies 1
    Last Activity 7 years, 5 months ago


    I'm trying to set an attribute on a specific element.

    The way I want to do this, is to iterate through the xml-elements and set the attribute.

    What I got so fare is that I could use the code beneath to actually set the attribute:

    [code]var rng = ActiveDocument.Range;
    if(rng.MoveToElement(“Section”)) {
    rng.ContainerAttribute(“numbering”) = “on”[/code]

    With this code it just set the first section elements attribute to “on”. After some head-scratching here
    I can't figure this out.

    How do I apply this code to iterate through all the sections elements?
    Or is there some other way to set this attribute?

    I could set the attribute as default “on” in the DTD, but I want the value to be stored in the xml-file.




    Derek Read

    Reply to: Using the MoveToElement method to set attribute values

    Something like this?

    [code]var rng = ActiveDocument.Range;
    while (rng.MoveToElement(“Section”)) {
    rng.ContainerAttribute(“numbering”) = “on”;

    The verbose version (with JScript comments):
    [code]//create a Range object named rng
    //this is created at the user's current selection in the document
    var rng = ActiveDocument.Range;

    //move the rng to the start of the document

    //repeatedly move to the next element named “Section” until that fails
    //and each time that is successful do whatever is inside the loop's {}
    while (rng.MoveToElement(“Section”)) {
    //set the value for the “numbering” attribute inside the current rng's container to “on”
    rng.ContainerAttribute(“numbering”) = “on”;


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

Lost Your Password?