Giter Site home page Giter Site logo

xpointer-example's Introduction

XInclude and XPointer example

An Example with XInclude and XPointer and how to reference them using IDs.

Process the file with:

$ xmllint --xinclude article.xml

The file article.xml contains different XIncludes and XPointers:

  • xi:include href="author.xml" xpointer="xpointer(element(/1)/*)"/>

    This is kind of what we know from SLE. Here it means: Include the "author.xml" file, start with the root element and return all children

  • <xi:include href="author.xml" xpointer="xpointer(id('author')/*)"/>

    Includes the file author.xml, points to the element with the xml:id "author" (that would be <author>, the root element), and return all children.

  • xi:include xpointer="xpointer(id('editor')/*)"/>

    This is something special: it doesn't have an href attribute! That means, it points to the current document (which is article.xml). The XPointer points to the element with the xml:id "editor" and returns all it's children.

  • <xi:include href="intro.xml" xpointer="xmlns(d=http://docbook.org/ns/docbook)xpointer(id('sec.intro')/*[not(self::d:title)])"/>

    For the XML nerds. ;-) Includes the file intro.xml, and points to the section with the xml:id "sec.intro". Include all elements except the title element. Useful if you want to specify another title. Use sparingly! (The xmlns() expression is needed to define the DocBook 5 namespace for the XPointer.)

xpointer-example's People

Contributors

tomschr avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Forkers

opensource438

xpointer-example's Issues

Getting errors trying the examples

I wanted to see an example of xpointer and Google brought me here.

I get some errors running xmllint --xinclude article.xml. Is there anything else I need to do to run without errors?

Here's what happens:

$ xmllint --version
xmllint: using libxml version 20910
   compiled with: Threads Tree Output Push Reader Patterns Writer SAXv1 FTP HTTP DTDValid HTML Legacy C14N Catalog XPath XPointer XInclude Iconv ISO8859X Unicode Regexps Automata Schemas Schematron Modules Debug Zlib Lzma 
$ xmllint --xinclude article.xml
XPath error : Invalid expression
article.xml:21: element include: XInclude error : XPointer evaluation failed: #xpointer(element(/1)/*)
article.xml:21: element include: XInclude error : could not load author.xml, and no fallback was found
<?xml version="1.0" encoding="UTF-8"?>
<?xml-model href="http://docbook.org/xml/5.1/rng/docbookxi.rng" schematypens="http://relaxng.org/ns/structure/1.0"?>
<?xml-model href="http://docbook.org/xml/5.1/sch/docbook.sch" type="application/xml" schematypens="http://purl.oclc.org/dsdl/schematron"?>
<article xmlns="http://docbook.org/ns/docbook" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:xlink="http://www.w3.org/1999/xlink" version="5.1" xml:lang="en">
 <title>Article with XIncludes and XPointer</title>
 <info>
  <authorgroup>
   <?xml-model href="http://docbook.org/xml/5.1/rng/docbookxi.rng" schematypens="http://relaxng.org/ns/structure/1.0"?><?xml-model href="http://docbook.org/xml/5.1/sch/docbook.sch" type="application/xml" schematypens="http://purl.oclc.org/dsdl/schematron"?><author xmlns="http://docbook.org/ns/docbook" version="5.1" xml:id="author">
   <personname>
    <firstname>Tux</firstname>
    <surname>Penguin</surname>
   </personname>
</author>
   <editor xml:id="editor">
    <personname>
     <firstname>Wilber</firstname>
     <surname>Gimp</surname>
    </personname>
   </editor>
  </authorgroup>
 </info>
 <para>
  (1) Hello, this is the author: <xi:include href="author.xml" xpointer="xpointer(element(/1)/*)"/>
 </para>
 <para>
  (2) This is the author: <personname xmlns="http://docbook.org/ns/docbook">
    <firstname>Tux</firstname>
    <surname>Penguin</surname>
   </personname>
 </para>
 <para>
  (3) This is the editor: <personname xmlns="http://docbook.org/ns/docbook">
     <firstname>Wilber</firstname>
     <surname>Gimp</surname>
    </personname>
 </para>

 <!-- (4) -->
 <note>
   <title xmlns="http://docbook.org/ns/docbook">Ignored Files in <filename>/etc/sudoers.d</filename></title><para xmlns="http://docbook.org/ns/docbook"> The <literal>#includedir</literal> command in
    <filename>/etc/sudoers</filename>, used for
    <filename>/etc/sudoers.d</filename>, ignores files that end in
    <literal>~</literal> (tilde) or contain a <literal>.</literal> (dot).
  </para>
 </note>

 <!-- (5) -->
 <sect1 xml:id="sec.intro-with-other-id">
   <title xmlns="http://docbook.org/ns/docbook">Introduction</title><para xmlns="http://docbook.org/ns/docbook">The quick brown fox jumps over the lazy dog.</para>
    <!-- (6) reuse the note again, but set your own ID: -->
    <note xml:id="note.sudoers.again">
     <title xmlns="http://docbook.org/ns/docbook">Ignored Files in <filename>/etc/sudoers.d</filename></title><para xmlns="http://docbook.org/ns/docbook"> The <literal>#includedir</literal> command in
    <filename>/etc/sudoers</filename>, used for
    <filename>/etc/sudoers.d</filename>, ignores files that end in
    <literal>~</literal> (tilde) or contain a <literal>.</literal> (dot).
  </para>
    </note>
 </sect1>

 <!-- (7) -->
 <sect1 xml:id="sec.intro-with-other-title">
   <title>Hello World</title>
   <!-- For the real XML nerd. It works, but better avoid it.
       With this notation, you can add a different title.
   -->
   <para xmlns="http://docbook.org/ns/docbook">The quick brown fox jumps over the lazy dog.</para>
 </sect1>

 <!-- (8) -->
 <sect1 xml:id="sec.intro-with-element-scheme">
   <title>Hello World with element()</title>
   <!-- Same as sec.intro-with-other-title, but a bit simpler.
   -->
   <para xmlns="http://docbook.org/ns/docbook">The quick brown fox jumps over the lazy dog.</para>
 </sect1>

</article>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.