%%% XML reading tests

:- eval(test_xml2()).

test_xml2() :-
	xml_root(Document,Root),
	RootAttributes = Root.getAttributes(),
println(["Root attributes: ",RootAttributes]),
	Elements = Root.getElementsByTagName("child"),
println(["Elements: ",Elements]),
	% This extends the standard DOM API: enumerate the nodes
	Elements.nodes(Element),
println(["Element: ",Element]),
	Attributes = Element.getAttributes(),
println(["Attributes: ",Attributes]),
	% This extends the standard DOM API: enumerate the nodes
	Attributes.nodes(Attribute),
	AttributeName=Attribute.getName(),
	AttributeValue=Attribute.getValue(),
println(["Attribute:",AttributeName,AttributeValue]," ")
	.

xml_root(Document,Root) :-
	StringReader=java.io.StringReader("<root><child attname='attvalue'></child></root>"),
println(["StringReader: ",StringReader]),
	% This extends the standard DOM API: create a Document based on Reader
	Document=XML(StringReader),
println(["XML document read: ",Document]),
	Root = Document.getDocumentElement(),
println(["XML root element: ",Root]).
