Home Forums General XMetaL Discussion Finding and returning exact insert location Reply To: Finding and returning exact insert location


Reply to: Finding and returning exact insert location


I use “XMetal Author Entreprise 9.0” and I have a problem with inserting at correct location.

My XML file has a number of “” elements which contain each a “” element.</p> <p><documentinfo><br />  <title>…

My XML shema specify that “” tag must be inserted after “” element.</p> <p>When using my macro, the “<language>” element is always inserted before the “<title>” and not after.</p> <p>“…<br />AddElement(“//documentInfo”, “language”, elementValue);<br />…”</p> <p>function AddElement(elementsName, elementName, elementValue)<br />{    <br />    var objNode = ActiveDocument.documentElement;<br />    var objNodesList = objNode.getNodesByXPath(elementsName);</p> <p>    for (var index = 0; index < objNodesList.length; index++)<br />    {<br />        objRange = ActiveDocument.Range;<br />        objRange.SelectNodeContents(objNodesList.item(index));<br />        objRange.SelectElement();<br />        objRange.Collapse(1);<br />        if (objRange.FindInsertLocation(elementName, true))<br />        {<br />            objRange.InsertWithTemplate(elementName);<br />            objRange.TypeText (elementValue);<br />        }<br />        else<br />        {<br />            ActiveDocument.Host.Alert(“Insert location not found.”);<br />        }        <br />    }            <br />}</p> <p>***</p> <p>Other problem :</p> <p>When “objRange” is “<practiceareas>” which is an element which contain “<practicearea>“, the instruction “objRange.FindInsertLocation(“practiceArea”, true)” won't find any valid insert location.</p> <p>Final ouput should be</p> <p><documentinfo><br />  <title>…