P
Paul Lee
Hi all,
I'm trying to use a Java written search code to traverse a DOM
hierarchy.
I'm mainy using code that I obtained from the Sun website. Basically,
in
main(), I have
Element rootElement = XML_document.getDocumentElement();
found_element = findElementNode("ATO_RawXML",
XML_document.getDocumentElement() );
where XML_document is of type Document.
The findElementNode function looks like this:
public static Node findElementNode(String name, Node node)
{
Node matchingNode = null;
//Check to see if root is the desired element. If so return root.
String nodeName = node.getNodeName();
if((nodeName != null) & (nodeName.equals(name)))
return node;
//Check to see if root has any children if not return null
if(!(node.hasChildNodes()))
return null;
//Root has children, so continue searching for them
NodeList childNodes = node.getChildNodes();
int noChildren = childNodes.getLength();
for(int i = 0; i < noChildren; i++){
if(matchingNode == null){
Node child = childNodes.item(i);
matchingNode = findElementNode(name,child);
} else break;
}
return matchingNode;
}
and my XML_document looks like:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<WfMessage>
<WfMessageHeader>
<ResponseRequired>Yes</ResponseRequired>
<UserContext>This data is sent back in response</UserContext>
</WfMessageHeader>
<ProcessTemplateExecute>
<ProcTemplateName>Generate And Disseminate FLY_</ProcTemplateName>
<ProcInstName>FLYPRO_Gen#1</ProcInstName>
<KeepName>true</KeepName>
<ProcInstInputData>
<_ACTIVITY_INFO>
<Priority>1</Priority>
</_ACTIVITY_INFO>
<ATO_ATO>
<ATO_FileLoadedIntoSystem>No</ATO_FileLoadedIntoSystem>
<ATO_RawXML>XML DATA HERE</ATO_RawXML>
</ATO_ATO>
</ProcInstInputData>
</ProcessTemplateExecute>
</WfMessage>
Using IBM WSAD, I put break points in during the for...next loop in
findElementNode, but it skips over the Node with the <ATO_RawXML>
tags.
In main(), found_element is null. What is wrong?
TIA,
Paul
I'm trying to use a Java written search code to traverse a DOM
hierarchy.
I'm mainy using code that I obtained from the Sun website. Basically,
in
main(), I have
Element rootElement = XML_document.getDocumentElement();
found_element = findElementNode("ATO_RawXML",
XML_document.getDocumentElement() );
where XML_document is of type Document.
The findElementNode function looks like this:
public static Node findElementNode(String name, Node node)
{
Node matchingNode = null;
//Check to see if root is the desired element. If so return root.
String nodeName = node.getNodeName();
if((nodeName != null) & (nodeName.equals(name)))
return node;
//Check to see if root has any children if not return null
if(!(node.hasChildNodes()))
return null;
//Root has children, so continue searching for them
NodeList childNodes = node.getChildNodes();
int noChildren = childNodes.getLength();
for(int i = 0; i < noChildren; i++){
if(matchingNode == null){
Node child = childNodes.item(i);
matchingNode = findElementNode(name,child);
} else break;
}
return matchingNode;
}
and my XML_document looks like:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<WfMessage>
<WfMessageHeader>
<ResponseRequired>Yes</ResponseRequired>
<UserContext>This data is sent back in response</UserContext>
</WfMessageHeader>
<ProcessTemplateExecute>
<ProcTemplateName>Generate And Disseminate FLY_</ProcTemplateName>
<ProcInstName>FLYPRO_Gen#1</ProcInstName>
<KeepName>true</KeepName>
<ProcInstInputData>
<_ACTIVITY_INFO>
<Priority>1</Priority>
</_ACTIVITY_INFO>
<ATO_ATO>
<ATO_FileLoadedIntoSystem>No</ATO_FileLoadedIntoSystem>
<ATO_RawXML>XML DATA HERE</ATO_RawXML>
</ATO_ATO>
</ProcInstInputData>
</ProcessTemplateExecute>
</WfMessage>
Using IBM WSAD, I put break points in during the for...next loop in
findElementNode, but it skips over the Node with the <ATO_RawXML>
tags.
In main(), found_element is null. What is wrong?
TIA,
Paul