|
Class: XMLCoder
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
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:]
instance creation
-
new
-
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
-
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.
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'].
]
].
|
|