Skip to content

savePos(xmlID, posLabel) and restorePos(xmlID, posLabel)

The savePos(xmlID, posLabel) method saves the current position specified by the posLabel attribute. It returns true if there is a current position, false otherwise.

For example, considering the following XML document, that has a current position as displayed:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<DOMAINTREE>                                                
    <DOMAIN NAME="1" LABEL="one">                           <-- Parent position
        <DOMAIN NAME="1.1" LABEL="one.one">                 <-- Main position
            <DOMAIN NAME="1.1.1" LABEL="one.one.one"/>      <-- Child position
            <DOMAIN NAME="1.1.2" LABEL="one.one.two"/>      
        </DOMAIN>
    </DOMAIN>
    <DOMAIN NAME="2" LABEL="two"/>                          
        <DOMAIN NAME="2.1" LABEL="two.one">                 
    <DOMAIN NAME="3" LABEL="three"/>
</DOMAINTREE>

The instruction:

XML.savePos(xmlID, "1.1");

saves the current position and returns a boolean true. If there is no current position or the file is not opened, the position is not saved and a boolean value of false is returned.

The syntax is:

XML.savePos(xmlID, posLabel)

where:

  • xmlID is the ID of the XML document.
  • posLabel is the attribute whose position is to be saved.

If in the meantime you changed the current position, for example you have a situation like the following:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<DOMAINTREE>                                                <-- Parent position
    <DOMAIN NAME="1" LABEL="one">                           
        <DOMAIN NAME="1.1" LABEL="one.one">                 
            <DOMAIN NAME="1.1.1" LABEL="one.one.one"/>      
            <DOMAIN NAME="1.1.2" LABEL="one.one.two"/>
        </DOMAIN>
    </DOMAIN>
    <DOMAIN NAME="2" LABEL="two"/>                          <-- Main position
        <DOMAIN NAME="2.1" LABEL="two.one">                 <-- Child position
    <DOMAIN NAME="3" LABEL="three"/>
</DOMAINTREE>

you can return at that position with the instruction:

restorePos(xmlID, "1.1");

The syntax is:

XML.restorePos(xmlID, posLabel)

where:

  • xmlID is the ID of the XML document.
  • posLabel is the attribute whose position has been saved with the savePos(xmlID, posLabel) method.

It returns true if there is a saved position, false otherwise.