<?xml version="1.0" encoding="UTF-8"?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<!DOCTYPE document PUBLIC "-//APACHE//DTD Documentation V2.0//EN" "http://forrest.apache.org/dtd/document-v20.dtd">
<document>
    <header>
        <title>Using Bookmarks to Annotate XML</title>
    </header>
    <body>
        <section>
            <title>Using Bookmarks to Annotate XML</title>

            <p>You can use a cursor to insert bookmarks that annotate XML with markers containing
                information you design. These bookmarks aren't written into the XML itself,
                but in a sense "hang" from the location where it was inserted. In this way
                you can associate arbitrary pieces of information with specific parts of the
                XML.
            </p>
            <p>You design your own bookmark classes by extending
                <strong>
                    <a href="ext:api/stable/XmlCursor.XmlBookmark">XmlBookmark</a>
                </strong>
                , a nested class of
                <strong>
                    <a href="ext:api/stable/XmlCursor">XmlCursor</a>
                </strong>
                .
                You can design your bookmark class to contain information specific to your
                needs.
            </p>
            <p>In the following example, <strong>OrderBookmark</strong> is
                an inner class that extends <strong>XmlCursor.XmlBookmark</strong>.
                It merely stores a piece of text.
            </p>
            <source><![CDATA[
            /*
             * The OrderBookmark class includes a constructor through which you will
             * insert your bookmark's content. It also includes get and set methods
             * you can use to retrieve and change the content.
             */
            static class OrderBookmark extends XmlCursor.XmlBookmark {
                public OrderBookmark (String text) { TEXT = text; }
                public String TEXT;
                public String getText() { return TEXT; }
                public void setText(String newText) { TEXT = newText; }
            }
        ]]></source>
            <p>You can use instances of this class to store bookmarks at places in your
                XML. The following excerpt of code creates a cursor and an instance of the
                <strong>OrderBookmark</strong>
                class. Then it uses the cursor
                to insert the bookmark at the cursor's current location.
            </p>
            <source><![CDATA[
            XmlCursor orderCursor = xmlDoc.newCursor();
            OrderBookmark thisBookmark = new OrderBookmark("foo");
            orderCursor.setBookmark(thisAnnotation);
        ]]></source>

        </section>

        <section id="relatedtopics">
            <title>Related Topics</title>
            <p>
                <a href="site:cursornav">Navigating XML with Cursors</a>
            </p>
        </section>
    </body>
</document>