Java Reference
In-Depth Information
System
.
err
.
println
(
">>>Parsing "
+
fileName
+
"..."
);
// Make the document a URL so relative DTD works.
String uri
=
"file:"
+
new
new
File
(
fileName
).
getAbsolutePath
();
DocumentBuilderFactory factory
=
DocumentBuilderFactory
.
newInstance
();
DocumentBuilder builder
=
factory
.
newDocumentBuilder
();
Document doc
=
builder
.
parse
(
uri
);
iif
(
verbose
)
System
.
err
.
println
(
">>>Walking "
+
fileName
+
"..."
);
doRecursive
(
doc
);
}
catch
catch
(
Exception ex
) {
System
.
err
.
println
(
"+============================+"
);
System
.
err
.
println
(
"| XTW Error |"
);
System
.
err
.
println
(
"+============================+"
);
System
.
err
.
println
(
ex
.
getClass
());
System
.
err
.
println
(
ex
.
getMessage
());
System
.
err
.
println
(
"+============================+"
);
}
iif
(
verbose
) {
System
.
err
.
println
(
">>>Done "
+
fileName
+
"..."
);
}
}
/* Process all the nodes, recursively. */
protected
protected
void
void
doRecursive
(
Node p
) {
iif
(
p
==
null
null
) {
return
return
;
}
NodeList nodes
=
p
.
getChildNodes
();
Debug
.
println
(
"xml-tree"
,
"Element has "
+
nodes
.
getLength
() +
" children"
);
for
for
(
int
int
i
=
0
;
i
<
nodes
.
getLength
();
i
++) {
Node n
=
nodes
.
item
(
i
);
iif
(
n
==
null
null
) {
continue
continue
;
}
doNode
(
n
);
}
}
protected
protected
void
void
doNode
(
Node n
) {