|
Class: XMLCoder
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
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:]
copyrightCOPYRIGHT (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.
instance creation
-
new
-
(comment from inherited method)
return an instance of myself without indexed variables
accessing
-
level
-
answer the current nesting level in the object/xml tree
-
level: something
-
-
prettyPrint
-
-
prettyPrint: something
-
set to true, to enable prettyPrinting (indentation) of XML text
-
version
-
return the value of the instance variable 'version' (automatically generated)
blocked
-
next
-
(comment from inherited method)
read, decode and return the next object
helpers
-
indent
-
indent line, if prettyPrinting is enabled
-
nextObject
-
this is sent, when an object has been encoded
-
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
-
emptyWriteStream
-
answer an empty stream. We represent encoded material as String
-
initialize
-
no limit
-
reset
-
reset the encoder to initial state
registration
-
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
-
newIdFor: anObject
-
register anObject and return anObject's id
-
remember: anObject as: id
-
register an object with a given id
-
rememberedIdFor: anObject
-
return anObject's id, if registered, nil if anObject has not been registered
-
version: something
-
set the version of the current xml output.
If not nil, it is stored as an attribute of the top element
representing
-
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
-
isDecoder
-
allows an xmlSpec to provide different spec-entries
-
isEncoder
-
allows an xmlSpec to provide different spec-entries
xml output
-
putAttribute: anAttributeNameString with: anObject
-
output an attribute to stream.
There are no attributes without attributeValue in
well-formed xml documents
-
putElement: anElementName attributes: attributeDictionary contents: aOneArgContentsBlock
-
write anObject to the encoder.
It is named nameOrIndex. Evaluate aBlock to encode its contents
-
putEndTag: tagString
-
-
putStartEndTag: tagString
-
-
putStartTag: tagString
-
-
putXmlHeader
-
write an xml standard header
-
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'.
]
|
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'].
]
].
|
|