XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreXML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 24th, 2004, 04:18 PM
sxk1900 sxk1900 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 7 sxk1900 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
parsing in jdom

I am trying to parse for an element which could be at any level inside an xml schema and return just the parents of that element using JDOM. I started the code but could not finish it..Could some one help me with the code..

for ex:
<rootElement>
<a>
<b>
<x>
<y>
<z></z>
</y>
</x>
</rootElement>

I have a method where I pass the element name z as an argument and I wish to get back..elements a and b are skipped.

<rootElement>
<x>
<y>
<z></z>
</y>
</x>
</rootElement>


private void parseschema( String elementName, String schemafilename) throws IOException {

boolean hasNoChildren=false;
SAXBuilder builder = new SAXBuilder();

try {
Document schemaDoc = builder.build(schemafilename);
List elements = schemaDoc.getRootElement().getChildren();
if ( elements.size()==0 ) {
hasNoChildren=true;
//throw an exception.
}
Iterator iElts = elements.iterator();
while (iElts.hasNext()) {
Element currElt = (Element) iElts.next();
String eleName = currElt .getName();
if (eleName.equals(elementName))
{
//match
}
else
{
//continue descent until match and return the parents
}
}

} catch (JDOMException e) {
throw new IOException(e.getMessage());
}
}

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > parsing in jdom


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT