I am new to jxpath, so please forgive my improper use of terminology or other 
ignorance.

I have a data structure consisting of nested maps and lists.  I am able to 
iterate over these elements with ease as long as I stick to a path-based xpaths 
("key1/key2/key3"), however, this approach fails if my keys contain illegal 
characters such as spaces.  To solve this problem, I translate these xpaths 
into predicate-based xpaths ("./[...@name='key 1']...@name='key 
2']...@name='key 3']).  This solves the illegal-character problem but breaks 
the ability to iterate over lists.  My impulse is to revert to path-based 
xpaths and create a map-wrapper exposes url-encoded keys in its API, but it 
occurs to be that there must be an easier way.  Any suggestions?  Is there a 
way to use the @name= notation while retaining the ability to iterate?  I am 
hoping for some kind of [*] delimiter to put in the xpath.

    List<Map> records = new ArrayList<Map>();
    Map record = new HashMap();
    records.add(record);
    List<Map> families = new ArrayList<Map>();
    record.put("Families", families);
    Map family = new HashMap();
    families.add(family);
    family.put("Wife", "Karen");
    JXPathContext rootContext = JXPathContext.newContext(dataMap);
    String xpath = "Families/Wife";
    assertNotNull("Blank Wife", rootContext.getValue(xpath));
    Iterator pointerIterator = rootContext.iteratePointers(xpath);
    assertTrue("Missing next Wife.", pointerIterator.hasNext());
    xpath = "....@name = 'Families']...@name = 'Wife']";
    assertNotNull("Blank encoded Wife", rootContext.getValue(xpath));
    pointerIterator = rootContext.iteratePointers(xpath);
    assertTrue("Missing next encoded Wife.", pointerIterator.hasNext()); // 
Fails here

Thanks in advance.

Paul Jackson

Reply via email to