XIncProc XPointer Processor > API Usage >

Base fixup option

XIncProc XPointer processor api support an option to fix xml:base attribute

Example

Given a simple xml :

            <doc  xmlns:xlink="http://www.w3.org/1999/xlink">
                <head id="h1">
                    <title>Virtual Library</title>
                </head>
                <body xml:base="http://example.org/today/">
                <paragraph>See <link xlink:type="simple" xlink:href="new.xml">what's
                    new</link>!</paragraph>
                <paragraph>Check out the hot picks of the day!</paragraph>
                <olist xml:base="/hotpicks/">
                    <item id="it1">
                        <link xlink:type="simple" xlink:href="pick1.xml">Hot Pick #1</link>
                    </item>
                    <item>
                        <link xlink:type="simple" xlink:href="pick2.xml">Hot Pick #2</link>
                    </item>
                    <item>
                        <link xlink:type="simple" xlink:href="pick3.xml">Hot Pick #3</link>
                    </item>
                </olist>
                </body>
            </doc>
        
  1. Instanciate a XPointerEngine:
                        final XPointerEngine xPointerEngine = new XPointerEngine();
                    
  2. Set the base fixup option to true
                        xPointerEngine.setBaseURI("test.xml");
                    
  3. Set the error handler and execute
                        final PrintableXPointerErrorHandler printableXPointerErrorHandler = new PrintableXPointerErrorHandler();
                        xPointerEngine.setXPointerErrorHandler(printableXPointerErrorHandler);
                        xPointerEngine.execute(pointer, new SAXSource(new InputSource(new StringReader(source))));
                    

Expressions matching nodes:

Pointer content Result Error
h1 <head xml:base="test.xml" id="h1"> <title xmlns:xlink="http://www.w3.org/1999/xlink">Virtual Library</title> </head>  
it1 <item xml:base="http://example.org/hotpicks/" id="it1"> <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="pick1.xml">Hot Pick #1</link> </item>  

With base fixup false:

                xPointerEngine.setBaseURI(null);
            

Pointer content Result Error
it1 <item id="it1"> <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="pick1.xml">Hot Pick #1</link> </item>