Wiki source for FunctionStAXgetNamespace

Show raw source

=====Function getNamespace=====

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

**getNamespace** returns the namespace uri of a START_ELEMENT event as string.

getNamepace( $event )


getNamepacereturns the name of an element.
The $event argument must be a START_ELEMENT event returned from [[FunctionStAXnextEvent nextEvent]].

To use the ""StAX"" functions you need to [[CommandImport import]] them into either the global namespace or a local namespace.
Its recommended that you use a local namespace so that there is less chance of name collisions.

Example: process every START_EVENT for element named "element" and print the attribute value for "attr"

Given an xml file "file.xml"
<file xmlns:a="">
<a:element attr="attr1"/>
<a:element attr="attr2">String</a:element>


import commands stax=stax
reader=stax:newEventReader( file.xml )
while [ stax:hasNext( $reader START_ELEMENT ) ] ; do
event=stax:nextEvent( $reader ) ;
name=stax:getName( $event )
ns=stax:getNamespace( $event )
xtype $ns $name
echo $ns $name

stax:closeReader $reader


net.sf.saxon.s9api.QName a:element
net.sf.saxon.s9api.QName a:element

[[FunctionsStAX StAX Functions]]
[[FunctionStAXnewEventReader newEventReader]]
[[FunctionStAXnextEvent nextEvent]]
[[JavaObjects Java Objects]]
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki