XBinder C# Runtime Library  2.8
Classes | Public Member Functions | Public Attributes | Properties | List of all members
com.objsys.xbinder.runtime.XBXmlEncoder Class Reference

Provides methods for encoding to XML (text). More...

Inheritance diagram for com.objsys.xbinder.runtime.XBXmlEncoder:

Public Member Functions

virtual void setNamespaces (XBXmlNamespace[] nsArray)
 
 XBXmlEncoder (System.IO.Stream ostream)
 Create an XBXmlEncoder on top of the given output More...
 
 XBXmlEncoder (System.IO.Stream ostream, System.String charsetName)
 Create an XBXmlEncoder on top of the given output More...
 
virtual System.String checkWellFormedElementAndContent (System.String xmlFragment)
 Parse the given XML fragment to ensure it is well-formed. The fragment must contain a single element and its content, and it must begin with the element start tag. More...
 
void enableUniqueAttrChecking ()
 For the current element only, turn on unique attribute checking. It must be invoked prior to the first encodeAttr; otherwise, the results are undefined. More...
 
virtual void encodeAttr (System.String name, System.String nsUri, System.String prefix, System.String value_Renamed)
 This method encodes an XML attribute value. More...
 
virtual void encodeAttrs (IList< XBAttributeBase > attrs)
 This method encodes the attributes in the given list. The prefix in the attribute is treated as a suggested prefix. More...
 
virtual void encodeChars (System.String data)
 Encode characters, applying escaping. More...
 
virtual void encodeCharsNoEscaping (System.String data)
 Encode characters, as is (without escaping). Users of this method should apply XML escaping when it may be needed. More...
 
virtual void encodeNamespace (XBXmlNamespace namespace_Renamed)
 Encode the given namespace on the next start element tag. If called after encodeStartElement, but before encoding any content (characters or child elements) for that element, the declaration will belong to that element. If called after encoding some content, or ending an element, the declaration will belong to the next element. More...
 
virtual void encodeStartElement (System.String elemName, System.String nsUri, System.String nsPrefix)
 This method encodes an XML start element tag. More...
 
virtual void encodeEndElement ()
 This method closes an element. If the start tag is still open (ie, no content was written), it will be closed with "/>". Otherwise, the most recently opened element is closed with "</qname>" More...
 
virtual void encodeXsiType (XBQualifiedName typeQName)
 Encode an xsi:type attribute for the given QName Eg. xsi:type="pre:name" More...
 
virtual void encodeStartDocument ()
 This method encodes standard header information at the beginning of the XML document. More...
 
void setCanonicalXML (bool value)
 

Public Attributes

const int XMLINDENT = 3
 

Properties

virtual int Indent [set]
 This method sets the number of spaces per indentation. If the value is set to zero, no indentation of the XML data is done. More...
 
virtual XBXmlNamespace [] Namespaces [set]
 Set the namespaces that should be encoded in the root element. Each namespace in the array will end up being declared. However, prefixes declared using encodeNamespaces take precedence, so that a prefix found in this array and also given to encodeNamespaces will be replaced with a generated prefix. Also, if a namespace is given a prefix by encodeNamespaces, the prefix given here will be ignored. More...
 

Detailed Description

Provides methods for encoding to XML (text).

This class is a Writer, so you can always use the Writer methods to directly write to the output stream. However, doing that has the obvious consequences that you are writing directly to the output stream and this class won't know anything about what you are doing.

Constructor & Destructor Documentation

◆ XBXmlEncoder() [1/2]

com.objsys.xbinder.runtime.XBXmlEncoder.XBXmlEncoder ( System.IO.Stream  ostream)

Create an XBXmlEncoder on top of the given output

(byte) stream. Characters will be encoded according to UTF-8. Output will be buffered.

Parameters
ostream

◆ XBXmlEncoder() [2/2]

com.objsys.xbinder.runtime.XBXmlEncoder.XBXmlEncoder ( System.IO.Stream  ostream,
System.String  charsetName 
)

Create an XBXmlEncoder on top of the given output

(byte) stream. Output will be buffered.

Parameters
ostream
charsetNameCharacters will be encoded according to the given charset name (see System.Text.Encoding class).

Member Function Documentation

◆ checkWellFormedElementAndContent()

virtual System.String com.objsys.xbinder.runtime.XBXmlEncoder.checkWellFormedElementAndContent ( System.String  xmlFragment)
virtual

Parse the given XML fragment to ensure it is well-formed. The fragment must contain a single element and its content, and it must begin with the element start tag.

Return the namespace for the element. If the element has a prefix, it will first be resolved according to the namespaces declared in the fragment. If this prefix is not declared, it will be resolved according to the currently declared namespaces known to this encoder. Calling this method has the side-effect of moving the encoder into the content of the current element, if it is not already there. This means you should make calls to encodeAttr and encodeNamespace prior to calling this method.

Parameters
xmlFragment
Returns
The namespace, or empty string, if there isn't one.

◆ enableUniqueAttrChecking()

void com.objsys.xbinder.runtime.XBXmlEncoder.enableUniqueAttrChecking ( )

For the current element only, turn on unique attribute checking. It must be invoked prior to the first encodeAttr; otherwise, the results are undefined.

By default, unique attribute checking is turned off. This is because the uniqueness of attributes is normally the result of data binding's mapping each declared attribute to a property. However, when wildcard attributes are in use, uniqueness is no longer guaranteed.

◆ encodeAttr()

virtual void com.objsys.xbinder.runtime.XBXmlEncoder.encodeAttr ( System.String  name,
System.String  nsUri,
System.String  prefix,
System.String  value_Renamed 
)
virtual

This method encodes an XML attribute value.

If a prefix is already declared for the namespace, it will be used. Otherwise, if the suggested prefix is not in use, it will be used. Otherwise, a prefix will be generated. Any prefix used but not declared will automatically be declared.

Parameters
nameAttribute name
nsUriThe attribute's namespace (empty if none)
prefixSuggested prefix
valueAttribute value in string form.

◆ encodeAttrs()

virtual void com.objsys.xbinder.runtime.XBXmlEncoder.encodeAttrs ( IList< XBAttributeBase attrs)
virtual

This method encodes the attributes in the given list. The prefix in the attribute is treated as a suggested prefix.

If a prefix is already declared for the namespace, it will be used. Otherwise, if the suggested prefix is not in use, it will be used. Otherwise, a prefix will be generated. Any prefix used but not declared will automatically be declared.

You should not modify the attribute objects you give to this method. The attribute objects may have their prefix changed.

Parameters
attrsThe attributes to encode.

◆ encodeChars()

virtual void com.objsys.xbinder.runtime.XBXmlEncoder.encodeChars ( System.String  data)
virtual

Encode characters, applying escaping.

Calling this method automatically closes any open element start tag.

◆ encodeCharsNoEscaping()

virtual void com.objsys.xbinder.runtime.XBXmlEncoder.encodeCharsNoEscaping ( System.String  data)
virtual

Encode characters, as is (without escaping). Users of this method should apply XML escaping when it may be needed.

Calling this method automatically closes any open element start tag.

◆ encodeEndElement()

virtual void com.objsys.xbinder.runtime.XBXmlEncoder.encodeEndElement ( )
virtual

This method closes an element. If the start tag is still open (ie, no content was written), it will be closed with "/>". Otherwise, the most recently opened element is closed with "</qname>"

◆ encodeNamespace()

virtual void com.objsys.xbinder.runtime.XBXmlEncoder.encodeNamespace ( XBXmlNamespace  namespace_Renamed)
virtual

Encode the given namespace on the next start element tag. If called after encodeStartElement, but before encoding any content (characters or child elements) for that element, the declaration will belong to that element. If called after encoding some content, or ending an element, the declaration will belong to the next element.

A prefix cannot be bound to two different namespaces in the same scope. To declare the default namespace, use an empty prefix.

◆ encodeStartDocument()

virtual void com.objsys.xbinder.runtime.XBXmlEncoder.encodeStartDocument ( )
virtual

This method encodes standard header information at the beginning of the XML document.

<throws> XBException Thrown, if operation is failed. </throws>

◆ encodeStartElement()

virtual void com.objsys.xbinder.runtime.XBXmlEncoder.encodeStartElement ( System.String  elemName,
System.String  nsUri,
System.String  nsPrefix 
)
virtual

This method encodes an XML start element tag.

The prefix provided is a suggestion. If the namespace is already mapped to some prefix, the existing prefix is used. Otherwise, if the prefix is not in use, it will be used. Otherwise, a prefix is generated.

No prefix is used when the namespace is the default namespace.

Whichever prefix is used, a namespace declaration will be automatically encoded, if necessary.

For every call to encodeStartElement, you should make a corresponding call to encodeEndElement.

Parameters
elemNameThe name of element.
nsUriThe element's namespace (possibly empty)
nsPrefixA suggested prefix for nsUri

<throws> XBException Thrown, if operation is failed. </throws>

◆ encodeXsiType()

virtual void com.objsys.xbinder.runtime.XBXmlEncoder.encodeXsiType ( XBQualifiedName  typeQName)
virtual

Encode an xsi:type attribute for the given QName Eg. xsi:type="pre:name"

The namespace for the QName should already be mapped to a prefix (or be the default namespace).

This method will determine the prefix to use inside the attribute value. This method may undeclare the default namespace (necessary if the given QName does not have a namespace).

Property Documentation

◆ Indent

virtual int com.objsys.xbinder.runtime.XBXmlEncoder.Indent
set

This method sets the number of spaces per indentation. If the value is set to zero, no indentation of the XML data is done.

Parameters
valueNumber of spaces per indentation level.

◆ Namespaces

virtual XBXmlNamespace [] com.objsys.xbinder.runtime.XBXmlEncoder.Namespaces
set

Set the namespaces that should be encoded in the root element. Each namespace in the array will end up being declared. However, prefixes declared using encodeNamespaces take precedence, so that a prefix found in this array and also given to encodeNamespaces will be replaced with a generated prefix. Also, if a namespace is given a prefix by encodeNamespaces, the prefix given here will be ignored.

To declare the default namespace, use an empty prefix. For the default namespace, declarations made with encodeNamespaces take precedence.