eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'XMLCoder':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: XMLCoder


Inheritance:

   Object
   |
   +--Visitor
      |
      +--AspectVisitor
         |
         +--ObjectCoder
            |
            +--XMLCoder
               |
               +--XMLStandardCoder

Package:
stx:goodies/xml/stx
Category:
XML-Presentation
Version:
rev: 1.24 date: 2017/05/23 10:33:31
user: stefan
file: XMLCoder.st directory: goodies/xml/stx
module: stx stc-classLibrary: stx
Author:
Stefan Vogel

Description:


Outputs Objects in XML format to a stream



[instance variables:]
    level (Integer)         Level do descent into the object tree
    indent (Integer)        Current indent depth for pretty-printing
    aspect (Object)         Aspect to be coded

[class variables:]


Related information:



Class protocol:

instance creation
o  new


Instance protocol:

accessing
o  level
answer the current nesting level in the object/xml tree

o  level: something

o  prettyPrint

o  prettyPrint: something
set to true, to enable prettyPrinting (indentation) of XML text

o  version
return the value of the instance variable 'version' (automatically generated)

blocked
o  next

helpers
o  indent
indent line, if prettyPrinting is enabled

o  nextObject
this is sent, when an object has been encoded

o  putObject: anObject element: elementName name: nameOrIndex class: className value: aBlock
write anObject to the encoder.
It is named nameOrIndex. Evaluate aBlock to encode its contents

initialization
o  emptyWriteStream
answer an empty stream. We represent encoded material as String

o  initialize
no limit

o  reset
reset the encoder to initial state

registration
o  newId
answer a unique id.
The id must be registered with: #remember:as: in order to make the id persistent.
The default here is to simply count the remembered objects starting at 1

o  newIdFor: anObject
register anObject and return anObject's id

o  remember: anObject as: id
register an object with a given id

o  rememberedIdFor: anObject
return anObject's id, if registered, nil if anObject has not been registered

o  version: something
set the version of the current xml output.
If not nil, it is stored as an attribute of the top element

representing
o  possiblyReferenced: anObject
return true, if anObject is subject to being referenced more than once.
If true, an ID is generated, and followup references are stored
as IDREFs, allowing for cyclic or self referencing structures to be
stored.

testing
o  isDecoder
allows an xmlSpec to provide different spec-entries

o  isEncoder
allows an xmlSpec to provide different spec-entries

xml output
o  putAttribute: anAttributeNameString with: anObject
output an attribute to stream.
There are no attributes without attributeValue in
well-formed xml documents

o  putElement: anElementName attributes: attributeDictionary contents: aOneArgContentsBlock
write anObject to the encoder.
It is named nameOrIndex. Evaluate aBlock to encode its contents

o  putEndTag: tagString

o  putStartEndTag: tagString

o  putStartTag: tagString

o  putXmlHeader
write an xml standard header

o  quoteString: aString
convert aString to a valid XML string and write it into stream.


Examples:


Usually you implement your XML coding as a visitor (see XMLStandardCoder). But you can as well encode something manually:
|coder|

String streamContents:[:stream |
    coder := XMLCoder on:stream.
    coder prettyPrint:true.

    coder putElement:'TOP'
          attributes:nil
          contents:[:coder|
              coder putElement:'FIRST'
                    attributes:(Dictionary withKeysAndValues:#(att1 val1 att2 nil att3 'complex value :<&>'))
                    contents:[:coder| coder quoteString:'hello world'].
              coder putElement:'SECOND'
                    attributes:(Dictionary withKeysAndValues:#(s1 val1 s2 nil s3 val3))
                    contents:[:coder| coder quoteString:'second element'].
          ]
].


ST/X 7.2.0.0; WebServer 1.670 at bd0aa1f87cdd.unknown:8081; Thu, 28 Mar 2024 18:00:02 GMT