Ignore:
Timestamp:
08/09/10 15:56:17 (22 months ago)
Author:
jharrop
Message:

Improved XPath mangling.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/docx4j/src/main/java/org/docx4j/openpackaging/parts/CustomXmlDataStoragePart.java

    r1166 r1183  
    291291                                xpathBase = xpath; 
    292292                        } 
     293                         
     294                        // Drop any trailing position  
     295                        if (xpathBase.endsWith("]"))  
     296                                xpathBase = xpathBase.substring(0, xpathBase.lastIndexOf("[")); 
     297                         
    293298                        log.debug("Repeat: using xpath: " + xpath); 
    294299                NamespaceContext nsContext = new NamespacePrefixMappings();                      
     
    364369                                                log.debug("existing xpath: " + thisXPath); 
    365370                                                 
    366                                                 // The tricky part 
     371                                                /* The tricky part: replace path segment 
     372                                                 *  
     373                                                 * For xpathBase=/invoice[1]/items 
     374                                                 *  
     375                                                 *  eg1  
     376                                                 *   
     377                                                                /invoice[1]/items/item[1]/name becomes 
     378                                                                /invoice[1]/items/   *[n]/name 
     379                                                                 
     380                                                         * eg2 
     381                                                         *       
     382                                                                /invoice[1]/items[1]/item[1]/name becomes 
     383                                                                /invoice[1]/items   /   *[n]/name 
     384                                                 */ 
    367385                                                if (thisXPath.startsWith(xpathBase)) { 
    368386                                                        log.debug("xpathBase: " + xpathBase); 
    369                                                         int beginIndex = thisXPath.indexOf("/", xpathBase.length()+1 ); // +1 for good measure                                                   
    370                                                         String newPath = xpathBase + "/*[" + (i+1) + "]/" + thisXPath.substring(beginIndex+1);                                                   
     387                                                        int beginIndex = thisXPath.indexOf("/", xpathBase.length()+1 ); // +1 for good measure     
     388                                                        int endIndex = thisXPath.indexOf("/", beginIndex+1 );  
     389                                                        if (endIndex<0) endIndex = beginIndex; 
     390                                                         
     391                                                        String newPath = xpathBase + "/*[" + (i+1) + "]/" + thisXPath.substring(endIndex+1); 
     392                                                         
    371393                                                        log.debug("newPath: " + newPath); 
    372394                                                        binding.setXpath(newPath); 
Note: See TracChangeset for help on using the changeset viewer.