|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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()); } } |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > parsing in jdom |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|