You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Uwe Barthel (JIRA)" <ji...@apache.org> on 2015/11/21 10:15:10 UTC

[jira] [Comment Edited] (JXPATH-169) getChildNodes() has problems in 3rd level of nesting.

    [ https://issues.apache.org/jira/browse/JXPATH-169?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15020347#comment-15020347 ] 

Uwe Barthel edited comment on JXPATH-169 at 11/21/15 9:14 AM:
--------------------------------------------------------------

[~rubengerad] Did you tried it with release 1.3?

As [~vivodamichele@hotmail.com] said, [~rubengerad] Could you provide a small test case?


was (Author: barthel):
As [~vivodamichele@hotmail.com] said, [~rubengerad] Could you provide a small test case?

> getChildNodes() has problems in 3rd level of nesting.
> -----------------------------------------------------
>
>                 Key: JXPATH-169
>                 URL: https://issues.apache.org/jira/browse/JXPATH-169
>             Project: Commons JXPath
>          Issue Type: Bug
>    Affects Versions: 1.2 Final
>         Environment: Windows, JDK 1.6
>            Reporter: Ruben Gerad Mathew
>
> In the event of using JXPath for reading an XML file, the getChildren() method  is not fetching NodeList after 3rd level, and any structure after 3rd level return #text (probably scrambled).  
> An XMI document with an UML structure was parsed, the objective was to identify all attributes inside a class within a package.  The context retrieves a list of pakages, getChildren() gets the classes embedded within it and getChildren() on each node on Class gets both the attributes and operations.  
> However we are unable to get the tagged values in attributes or look any deeper than 3 levels. I tried to get the name of the attribute and use xpath context lookup, but some reason it keeps failing.
> Some bit of the code to help.
> 	private void inspectClasses(String handle, Node eachEntryNode){
> 		try{
> 			UmlClass umlClass = new UmlClass();
> 			umlClass.setClassNamespace(eachEntryNode.getAttributes().getNamedItem("name").getNodeValue());
> 			umlClass.setXmiId(eachEntryNode.getAttributes().getNamedItem("xmi.id").getNodeValue());
> 			umlClass.setVisibility(eachEntryNode.getAttributes().getNamedItem("visibility").getNodeValue().toString());
> 			umlClass.setActiveClass(Boolean.parseBoolean(eachEntryNode.getAttributes().getNamedItem("isActive").getNodeValue().toString()));
> 			umlClass.setAbstractClass(Boolean.parseBoolean(eachEntryNode.getAttributes().getNamedItem("isAbstract").getNodeValue().toString()));
> 				for(int child =0; child<eachEntryNode.getChildNodes().getLength();child++){
> 	        		if(eachEntryNode.getChildNodes().item(child).getNodeName().equals("UML:ModelElement.taggedValue")){
> 	        			umlClass.setTaggedValue(getTaggedValues(eachEntryNode.getChildNodes().item(child).getChildNodes()));	        			
> 	        			EventLog.clog(this,"["+umlClass.getClassNamespace()+"] Tagged values :"+umlClass.getTaggedValue().size());        			
> 	        		}
> 	        		if(eachEntryNode.getChildNodes().item(child).getNodeName().equals("UML:Classifier.feature")){
> 	        			umlClass.setUmlAttributes(getClassAttributes(handle, eachEntryNode.getChildNodes().item(child)));
> 	        			EventLog.clog(this,"["+umlClass.getClassNamespace()+"] Tagged values :"+umlClass.getTaggedValue().size());        			
> 	        		}
> 	        		listClasses.add(umlClass);
> 				}
> 			}
>             catch(NullPointerException exp){        
>             }
> 			catch(Exception exp){
> 				ExceptionLog.clog(this, "Problem validating nodes! Error: "+exp.getMessage());
> 			}
> 	}
> public List<UmlAttribute> getClassAttributes(String handle, Node node){
> 		List<UmlAttribute> classAttributes = new ArrayList<UmlAttribute>();
> 		
> 		int child, y;
> 		try{		
> 			Document document=(Document)parsedDocs.get(handle);
> 			JXPathContext context = JXPathContext.newContext(document);
> 			context.setLenient(true);
> 			NodeList childNodes = node.getChildNodes();		
> 				for(child =0; child<childNodes.getLength();child++){
> 					if(childNodes.item(child).getNodeName().toString().equals("UML:Attribute")){
> 						Node thisNode = childNodes.item(child);
> 						NodeList listNodes =childNodes.item(child).getChildNodes();
> 						//List entries= context.selectNodes("//UML:Attribute"); //this was a out of the way attempt to get inside the next level of nested class attribute tag values
> 						EventLog.clog(this, "^^^^^^^^^^^^^^^  "+thisNode.getAttributes().getNamedItem("name").getNodeValue().toString());				
> 						locateAttribute(thisNode.getAttributes().getNamedItem("name").getNodeValue().toString(), listNodes); // unabale to iterate listNodes children. 3rd-4th level missing values and prints only #text as result.
> 					}
> 					//EventLog.clog(this, "***************  "+childNodes.item(child).getNodeName().toString());				
> 				}
> 			}catch(Exception exp){
> 			ExceptionLog.clog(this,"Problem orgnaizing namespace structure"+exp.getMessage());			
> 		}
> 		return classAttributes;
> 	}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)