Wiki source for FunctionStAXwriteAttribute


Show raw source

=====Command writeAttribute=====

This command is part of the [[FunctionsStAX StAX]] support.

====Name====
**writeAttribute** writes a single attribute to a ""StAX Writer"" created with [[FunctionStAXnewStreamWriter newStreamWriter]]

====Synopsis====
writeAttribute writer qname value


====Description====
writeAttribute writes a single attribute to a writer created with [[FunctionStAXnewStreamWriter newStreamWriter]]. It is only valid immedetely after a call to [[FunctionStAXwriteStartElement writeStartElement]] or [[FunctionStAXwriteAttribute writeAttribute]]

Note that unlike many of the ""StAX"" functions this is a command not a function. You use the Command syntax to invoke it.


The "qname" argument is the name of the attribute. This can be a simple name (becomes the localname), a QName in [[QNameClarkNotation Clark notation]] or a QName object (created by the [[FunctionQName QName]] function)



Example
%%
import commands stax=stax


w=stax:newStreamWriter()
stax:writeStartDocument $w
stax:writeStartElement $w foo
stax:writeAttribute $w a1 value1
stax:writeCharacters $w "Some Characters"
stax:writeEndElement $w
stax:writeEndDocument $w


stax:closeWriter $w


%%

Result
%%
<foo a1="value1">Some Characters</foo>
%%


----
[[Commands]]
[[FunctionsStAX StAX Functions]]
[[FunctionStAXnewStreamWriter newStreamWriter]]

[[JavaObjects Java Objects]]
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki