A
Arun
I have the following code
***********************************
/**
* Recurses through schema finding the first instance of the
element name
* @param schemaElement - current element being compared from
schema
* @param checkElement - element to be checked against i.e. the
node selected in the gui
* @return the element in schema which matches the checkElement
*/
private Element findElementNameMatch(Element schemaElement, Element
checkElement)
{
// Get list of children
List listOfChildren = schemaElement.getChildren();
// If element has children
if(listOfChildren.size() != 0)
{
// Recurse through all elements under this one
for(int x=0; x < listOfChildren.size(); x++)
{
// Get child element
Element childElement = (Element) listOfChildren.get(x);
if(childElement.getName() == checkElement.getName())
{
return(childElement);
}
findElementNameMatch(childElement,checkElement);
}
}
return(null);
}
***********************************
The method is trying to find an element in an xml document that matches
a given name.
Can anyone give me tips on how to go about returning a value from deep
recursion to the first recursion of that particular method, so it can
return that value to the method that called it.
And also quite importantly how to stop any recursions after a match has
been found. EG a target element is found and returned, but how can i
stop the recursion going on to check elements under this element.
So far i have only achieved the two by creating a global variable and
flag, the variable is initialised when the match is found, and flag is
set to true so no more recursions are done afterwards.
***********************************
/**
* Recurses through schema finding the first instance of the
element name
* @param schemaElement - current element being compared from
schema
* @param checkElement - element to be checked against i.e. the
node selected in the gui
* @return the element in schema which matches the checkElement
*/
private Element findElementNameMatch(Element schemaElement, Element
checkElement)
{
// Get list of children
List listOfChildren = schemaElement.getChildren();
// If element has children
if(listOfChildren.size() != 0)
{
// Recurse through all elements under this one
for(int x=0; x < listOfChildren.size(); x++)
{
// Get child element
Element childElement = (Element) listOfChildren.get(x);
if(childElement.getName() == checkElement.getName())
{
return(childElement);
}
findElementNameMatch(childElement,checkElement);
}
}
return(null);
}
***********************************
The method is trying to find an element in an xml document that matches
a given name.
Can anyone give me tips on how to go about returning a value from deep
recursion to the first recursion of that particular method, so it can
return that value to the method that called it.
And also quite importantly how to stop any recursions after a match has
been found. EG a target element is found and returned, but how can i
stop the recursion going on to check elements under this element.
So far i have only achieved the two by creating a global variable and
flag, the variable is initialised when the match is found, and flag is
set to true so no more recursions are done afterwards.