Saxon.Api

 

 

Saxon.Api

Class TextResource


public class TextResource
implements IResource

An implementation of IResource that represents plain text

Constructor Summary

TextResource (string content, Uri systemId)

Create a TextResource whose content is supplied as a constant string

TextResource (TextReader reader, Uri systemId)

Create a TextResource whose content is delivered using a TextReader

TextResource (Stream stream, Encoding encoding, Uri systemId)

Create a TextResource whose content is delivered using a Stream, with a specified encoding

TextResource (Stream stream, Uri systemId)

Create a TextResource whose content is delivered using a Stream, with an inferred encoding

TextResource (Stream stream, Uri systemId, Encoding encoding)

Create a TextResource whose content is delivered using a Stream, with an explicit encoding

 

Property Summary

 string Content

The content of the text resource, as a string

 string ContentType

The content type of the resource: always text/plain

 Stream InputStream

Get a Stream for reading the content of this resource in binary.

 Uri ResourceUri

The URI of the text resource

 TextReader TextReader

Get a TextReader for reading the content of this resource in character form

 

Method Summary

 XdmItem GetXdmItem ()

Return the content of the resource as an item

 bool hasReader ()

Ask whether the text resource has a known TextReader

 bool hasStream ()

Ask whether the text resource has a known input Stream

 

Constructor Detail

TextResource

public TextResource(string content,
                    Uri systemId)

Create a TextResource whose content is supplied as a constant string

Parameters:

content - The plain text content
systemId - The base URI of the content

TextResource

public TextResource(TextReader reader,
                    Uri systemId)

Create a TextResource whose content is delivered using a TextReader

Parameters:

reader - The TextReader used to deliver the content
systemId - The base URI of the content

TextResource

public TextResource(Stream stream,
                    Encoding encoding,
                    Uri systemId)

Create a TextResource whose content is delivered using a Stream, with a specified encoding

Parameters:

stream - The Stream used to deliver the content
encoding - The Encoding used to decode the binary contents of the stream
systemId - The base URI of the content

TextResource

public TextResource(Stream stream,
                    Uri systemId)

Create a TextResource whose content is delivered using a Stream, with an inferred encoding

Parameters:

stream - The Stream used to deliver the content
systemId - The base URI of the content

TextResource

public TextResource(Stream stream,
                    Uri systemId,
                    Encoding encoding)

Create a TextResource whose content is delivered using a Stream, with an explicit encoding

Parameters:

stream - The Stream used to deliver the content
systemId - The resource URI of the content, also used as the base URI
encoding - The Encoding used to decode the binary contents of the stream

Property Detail

Content

public string Content {get; }

The content of the text resource, as a string

Reading this property may cause any contained TextReader or Stream to be consumed and closed. The value will be retained internally and can be accessed repeatedly.

If the value needs to be obtained by reading a (binary) stream, the supplied encoding will be used if available; if not, the system attempts to infer an encoding from the content of the stream, for example by looking for a byte-order mark.

ContentType

public string ContentType {get; }

The content type of the resource: always text/plain

InputStream

public Stream InputStream {get; }

Get a Stream for reading the content of this resource in binary.

If an input stream is available, it is returned.

If a reader is available, or if the string content is available, then the content is read and a MemoryStream is returned delivering the content in UTF-8 encoding.

ResourceUri

public Uri ResourceUri {get; }

The URI of the text resource

TextReader

public TextReader TextReader {get; }

Get a TextReader for reading the content of this resource in character form

If an explicit TextReader is already available, it is returned.

If the content of the resource is available as a string, then a StringReader giving access to the content is returned.

If an input Stream is available, then a TextReader is constructed, taking account of the encoding if known, or with an inferred encoding otherwise.

As a last resort, a StringReader delivering a zero-length string is returned.

Method Detail

GetXdmItem

public XdmItem GetXdmItem()

Return the content of the resource as an item

Returns:

An XdmAtomicValue of type xs:string holding the content of the resource

hasReader

public bool hasReader()

Ask whether the text resource has a known TextReader

Returns:

True if there is an existing TextReader

hasStream

public bool hasStream()

Ask whether the text resource has a known input Stream

Returns:

True if there is an existing input Stream