org.eclipse.rdf4j.rio.rdfxml.util

## Class RDFXMLPrettyWriter

- java.lang.Object
- - org.eclipse.rdf4j.rio.helpers.AbstractRDFWriter
  - - org.eclipse.rdf4j.rio.rdfxml.RDFXMLWriter
    - - org.eclipse.rdf4j.rio.rdfxml.util.RDFXMLPrettyWriter

- All Implemented Interfaces:
    Closeable, Flushable, AutoCloseable, RDFHandler, RDFWriter

      public class RDFXMLPrettyWriter
      extends RDFXMLWriter
      implements Closeable, Flushable

  An extension of RDFXMLWriter that outputs a more concise form of RDF/XML. The resulting output is semantically equivalent to the output of an RDFXMLWriter (it produces the same set of statements), but it is usually easier to read for humans.

  This is a quasi-streaming RDFWriter. Statements are cached as long as the striped syntax is followed (i.e. the subject of the next statement is the object of the previous statement) and written to the output when the stripe is broken.

  The abbreviations used are typed node elements, empty property elements and striped syntax. Note that these abbreviations require that statements are written in the appropriate order.

  Striped syntax means that when the object of a statement is the subject of the next statement we can nest the descriptions in each other.

  Example:

       <rdf:Seq>
          <rdf:li>
             <foaf:Person>
                <foaf:knows>
                   <foaf:Person>
                     <foaf:mbox rdf:resource="..."/>
                   </foaf:Person>
                </foaf:knows>
             </foaf:Person>
          </rdf:li>
       </rdf:Seq>

  Typed node elements means that we write out type information in the short form of

       <foaf:Person rdf:about="...">
           ...
        </foaf:Person>

  instead of

       <rdf:Description rdf:about="...">
          <rdf:type rdf:resource="http://xmlns.com/foaf/0.1/Person"/>
           ...
        </rdf:Description>

  Empty property elements are of the form

       <foaf:Person>
          <foaf:homepage rdf:resource="http://www.cs.vu.nl/˜marta"/>
       </foaf:Person>

  instead of

       <foaf:Person>
          <foaf:homepage>
             <rdf:Description rdf:about="http://www.cs.vu.nl/˜marta"/>
          <foaf:homepage>
       </foaf:Person>

  Author:
    Peter Mika (pmika@cs.vu.nl)

- - ### Field Summary

    - ### Fields inherited from class org.eclipse.rdf4j.rio.rdfxml.RDFXMLWriter

      `baseIRI, defaultNamespace, headerWritten, lastWrittenSubject, writer, writingStarted`

    - ### Fields inherited from class org.eclipse.rdf4j.rio.helpers.AbstractRDFWriter

      `namespaceTable`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `RDFXMLPrettyWriter(OutputStream out)` Creates a new RDFXMLPrintWriter that will write to the supplied OutputStream.
    `RDFXMLPrettyWriter(OutputStream out, ParsedIRI baseIRI)` Creates a new RDFXMLPrintWriter that will write to the supplied OutputStream.
    `RDFXMLPrettyWriter(Writer out)` Creates a new RDFXMLPrintWriter that will write to the supplied Writer.
    `RDFXMLPrettyWriter(Writer writer, ParsedIRI baseIRI)` Creates a new RDFXMLPrintWriter that will write to the supplied Writer.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `close()`
    `void` | `flush()`
    `protected void` | `flushPendingStatements()`
    `void` | `handleStatement(Statement st)` Handles a statement.
    `protected void` | `writeHeader()`
    `protected void` | `writeIndents(int n)` Writes `n` indents.
    `protected void` | `writeStartTag(String namespace, String localName)`

    - ### Methods inherited from class org.eclipse.rdf4j.rio.rdfxml.RDFXMLWriter

      `endRDF, getRDFFormat, getValidNodeId, handleComment, handleNamespace, setNamespace, startRDF, writeAttribute, writeAttribute, writeCharacterData, writeEndOfEmptyTag, writeEndOfStartTag, writeEndTag, writeIndent, writeNewLine, writeStartOfStartTag`

    - ### Methods inherited from class org.eclipse.rdf4j.rio.helpers.AbstractRDFWriter

      `getSupportedSettings, getWriterConfig, set, setWriterConfig`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface org.eclipse.rdf4j.rio.RDFWriter

      `getSupportedSettings, getWriterConfig, set, setWriterConfig`

- - ### Constructor Detail

    - #### RDFXMLPrettyWriter

          public RDFXMLPrettyWriter(OutputStream out)

      Creates a new RDFXMLPrintWriter that will write to the supplied OutputStream.
      Parameters:
        `out` - The OutputStream to write the RDF/XML document to.

    - #### RDFXMLPrettyWriter

          public RDFXMLPrettyWriter(OutputStream out,
                                    ParsedIRI baseIRI)

      Creates a new RDFXMLPrintWriter that will write to the supplied OutputStream.
      Parameters:
        `out` - The OutputStream to write the RDF/XML document to.

    - #### RDFXMLPrettyWriter

          public RDFXMLPrettyWriter(Writer out)

      Creates a new RDFXMLPrintWriter that will write to the supplied Writer.
      Parameters:
        `out` - The Writer to write the RDF/XML document to.

    - #### RDFXMLPrettyWriter

          public RDFXMLPrettyWriter(Writer writer,
                                    ParsedIRI baseIRI)

      Creates a new RDFXMLPrintWriter that will write to the supplied Writer.
      Parameters:
        `out` - The Writer to write the RDF/XML document to.

  - ### Method Detail

    - #### writeHeader

          protected void writeHeader()
                              throws IOException

      Overrides:
        `writeHeader` in class `RDFXMLWriter`
      Throws:
        `IOException`

    - #### flush

          public void flush()
                     throws IOException

      Specified by:
        `flush` in interface `Flushable`
      Throws:
        `IOException`

    - #### close

          public void close()
                     throws IOException

      Specified by:
        `close` in interface `Closeable`
      Specified by:
        `close` in interface `AutoCloseable`
      Throws:
        `IOException`

    - #### flushPendingStatements

          protected void flushPendingStatements()
                                         throws IOException,
                                                RDFHandlerException

      Overrides:
        `flushPendingStatements` in class `RDFXMLWriter`
      Throws:
        `IOException`
        `RDFHandlerException`

    - #### handleStatement

          public void handleStatement(Statement st)
                               throws RDFHandlerException

      Description copied from interface: `RDFHandler`
      Handles a statement.
      Specified by:
        `handleStatement` in interface `RDFHandler`
      Overrides:
        `handleStatement` in class `RDFXMLWriter`
      Parameters:
        `st` - The statement.
      Throws:
        `RDFHandlerException` - If the RDF handler has encountered an unrecoverable error.

    - #### writeStartTag

          protected void writeStartTag(String namespace,
                                       String localName)
                                throws IOException

      Throws:
        `IOException`

    - #### writeIndents

          protected void writeIndents(int n)
                               throws IOException

      Writes `n` indents.
      Throws:
        `IOException`

Copyright © 2015-2020 Eclipse Foundation. All Rights Reserved.