XIncProc XPointer Processor > API Usage >

Lang fixup option

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

Example

Given a simple xml :

            
                <sentences>
                <sentence id="none">Hi.</sentence>
                <sentence id="english" xml:lang="en-gb">Hello.</sentence>
                <sentence id="french" xml:lang="fr">Bonjour.</sentence>
                <sentences xml:lang="en-gb">
                <sentence id="english2">Hello.</sentence>
                </sentences>
                <sentences xml:lang="de">
                <sentence id="german">Guten Tag.</sentence>
                <sentences xml:lang="en-au">
                <sentence id="australian">G'day mate.</sentence>
                </sentences>
                <sentences xml:lang="">
                <sentence id="none2">Yo..</sentence>
                </sentences>
                </sentences>
                </sentences>
            
        
  1. Instanciate a XPointerEngine:
                        final XPointerEngine xPointerEngine = new XPointerEngine();
                    
  2. Set the lang
                        xPointerEngine.setLang(langfixup);
                    
  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 Lang fixup Result Error
none (null) <sentence id="none">Hi.</sentence>  
none2 (null) <sentence id="none2">Yo..</sentence>  
english (null) <sentence xml:lang="en-gb" id="english">Hello.</sentence>  
english2 (null) <sentence xml:lang="en-gb" id="english2">Hello.</sentence>  
french (null) <sentence xml:lang="fr" id="french">Bonjour.</sentence>  
german (null) <sentence xml:lang="de" id="german">Guten Tag.</sentence>  
australian (null) <sentence xml:lang="en-au" id="australian">G'day mate.</sentence>  
none en-gb <sentence xml:lang="" id="none">Hi.</sentence>  
none2 en-gb <sentence xml:lang="" id="none2">Yo..</sentence>  
english en-gb <sentence xml:lang="en-gb" id="english">Hello.</sentence>  
english2 en-gb <sentence id="english2">Hello.</sentence>  
french en-gb <sentence xml:lang="fr" id="french">Bonjour.</sentence>  
german en-gb <sentence xml:lang="de" id="german">Guten Tag.</sentence>  
australian en-gb <sentence xml:lang="en-au" id="australian">G'day mate.</sentence>