General XMetaL Discussion

XMetaL Community Forum General XMetaL Discussion Function "FindInsertLocation" doesn’t seem to work correctly

  • rewers08

    Function "FindInsertLocation" doesn’t seem to work correctly

    Participants 2
    Replies 3
    Last Activity 12 years ago


    we are using XMAX 5.5.
    In an XML-File supported by a XML-Schema we use the function “findInsertLocation” to find the insert location for a certain tag. We use this function in quite many places and in most of the cases it works just fine. In the following example it doesn't work and I can't see why:

    What we want to do is to insert “Element A_3” which – according to the XML-Schema – can be inserted inbetween “Element A_2” and “Element A_4”. If I place the cursor between these two elements in XMetaL or XMAX I can choose “Element A_3” from the Elements-Window. I see this as a proof that the Schema is correct and XMAX and XMetaL interpret it correctly. We have a Macro (JS) which uses the following call of findInsertLocation:

    if( !rng.FindInsertLocation(“Element_A_3”), true) {
    rng.FindInsertLocation(“Element_A_3”, false);

    According to my understanding this will make XMAX look for an insert location for “Element_A_3”. It will first look forward starting from the current cursor location. If it can't find the insert location it will look backwards. I would expect XMAX to move the Range to the approriate position. But the Range remains unchanged. Could it be that the function is not working correctly? Am I missing something? I am quite sure that the following things are correct:

    – XML-Schema
    – XML file is valid
    – JavaScript is correct

    Thanks in advance,


    Derek Read

    Reply to: Function "FindInsertLocation" doesn’t seem to work correctly

    In our testing here the function is working properly, but it is possible we have not covered all possible test cases. So, it is best if you can provide the schema and the XML instance so we can reproduce the issue. If you do not wish to post those files here please submit a support case with XMetaL Support.

    Please also test in both Tags On and Normal view to see if the behavior is the same. In this case (as Range is used) there should be no difference, but if you have uncovered a bug there may be a difference (eg: it works in one view but not the other, or it doesn't work in either but slightly differently, etc).



    Reply to: Function "FindInsertLocation" doesn’t seem to work correctly

    Thanks for your fast reply.

    It seems that we made a mistake. Before calling the findInsertLocation function we called the function rng.SelectNodeContents on the document's root node. I changed the call to rng.SelectBeforeNode on the root node. Now everything seems to work fine.

    Sorry for the false alarm.



    Derek Read

    Reply to: Function "FindInsertLocation" doesn’t seem to work correctly

    I see, that would do it. Thanks for clearing this up.


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

Lost Your Password?