473,394 Members | 1,778 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Why isn't my DOM search code working?

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
Jul 20 '05 #1
2 4566


Paul Lee wrote:

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() );


Is there any reason you can't use the
getElementsByTagName
method of the document node or any element node to solve that?
--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #2

"Martin Honnen" <ma*******@yahoo.de> wrote in message
news:40********@olaf.komtel.net...


Paul Lee wrote:

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() );


Is there any reason you can't use the
getElementsByTagName
method of the document node or any element node to solve that?

The only reason I didn't use that is because I simply couldn't get it to
work
- maybe I got the syntax wrong (I was using the Sun website as a
reference).

Best wishes

Paul
--
http://www.paullee.com

Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Steph | last post by:
Hi. I'm very new to MS Access and have been presented with an Access database of contacts by my employer. I am trying to redesign the main form of the database so that a button entitled...
4
by: Tarique Jawed | last post by:
Alright I needed some help regarding a removal of a binary search tree. Yes its for a class, and yes I have tried working on it on my own, so no patronizing please. I have most of the code working,...
5
by: pembed2003 | last post by:
Hi all, I need to write a function to search and replace part of a char* passed in to the function. I came up with the following: char* search_and_replace(char* source,char search,char*...
0
by: Hriday | last post by:
Hi there, I am working on a web application in ASP.NET My web server and AD machine are in the same domain but located on diffrent phisical machine, I am not able to search user's info by the...
5
gekko3558
by: gekko3558 | last post by:
I am writing a simple binary search tree (nodes are int nodes) with a BSTNode class and a BST class. I have followed the instructions from my C++ book, and now I am trying to get a remove method...
2
by: princymg | last post by:
I want to search a file from server and want to copy it to the local disk. how it is done? This is working if the file is in my hard disk itself.But not when it comes to server. If i map the server...
2
by: princymg | last post by:
I want to search a file from server and want to copy it to the local disk. how it is done? This is working if the file is in my hard disk itself.But not when it comes to server. If i map the server...
12
by: iahamed | last post by:
Hi Everyone, I got two parts of my advance search to work, I am running out of Logic to connect the third. My mind is in swing! Pleaseeeeeeeee Help me. I have 3 Fiels to search, the First two...
6
by: woodey2002 | last post by:
Hi Everyone. Thanks for your time. I am trying to create a search form that will allow users to select criteria from multiple multi select boxes. So far i have managed to achieve a search option...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.