Java Reference
In-Depth Information
or using only the Node interface:
Node child # node.getFirstChild();
while(child! # null){
child # child.getNextSibling();
Usually the navigation is driven by some criteria. Often we are interested in
looking at elements of a given type. For instance, in order to visit all the top-level
elements of a document having a given TAG we can use the following fragment of
Document doc # ... ;
// get the list of elements having tag "TAG"
NodeList elements # doc.getElementsByTagName("TAG");
for ( int i # 0; i<elements.getLength(); !! i){
// access the i-th element; since NodeList
// contains node we need to cast it to Element
Element element # (Element)elements.item(i);
// ...
Elements can contain embedded elements such as any node; in addition they
may have attributes that contain string values. Interface Element provides easy
access to any attribute value through method getAttribute() that takes the
attribute name as parameter.
Element element # ... ;
String value # element.getAttribute("NAME");
Since JAXP has been designed for genericity, the parsing of an XML documents
requires a sequence of steps:
// the parsing of XML documents is based on the
// DocumentBuilderFactory class
DocumentBuilderFactory dbf # DocumentBuilderFactory.
// the XML parser is implemented by the DocumentBuilder
// class that is created by the relative factory
DocumentBuilder parser # dbf.newDocumentBuilder();
// the XML document can be obtained by parsing a file
Document doc # parser.parse(new File("test.xml"));
All of the classes that make up this component are in a single package:
ProcessDefinition . This simplifies the integration with the other components
in the following prototypes.
The main class that is also the entry point to load the process description
from an XML file is WfProcessDefinition . The class has a set of getter methods
to access the read-only attributes, and the method initialActivities() that
Search WWH ::

Custom Search