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.29 date: 2021/08/30 13:20:32
user: cg
file: XMLCoder.st directory: goodies/xml/stx
module: stx stc-classLibrary: stx

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:]

copyright

COPYRIGHT (c) 1999 by eXept Software AG All Rights Reserved This software is furnished under a license and may be used only in accordance with the terms of that license and with the inclusion of the above copyright notice. This software may not be provided or otherwise made available to, or used by, any other person. No title to or ownership of the software is hereby transferred.

Class protocol:

instance creation
o  new
(comment from inherited method)
return an instance of myself without indexed variables


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
(comment from inherited method)
read, decode and return the next object

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.

Usage example(s):

    String streamContents:[:stream |
        |coder|

        coder := XMLCoder on:stream.
        coder quoteString:'hello'.
        coder quoteString:'hello'.
    ]


Examples:


Usually you implement your XML coding as a visitor (see XMLStandardCoder). But you can as well encode something manually:
String streamContents:[:stream |
    |coder|
    coder := XMLCoder on:stream.
    coder prettyPrint:true.

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


ST/X 7.7.0.0; WebServer 1.702 at 20f6060372b9.unknown:8081; Tue, 22 Oct 2024 14:26:41 GMT