commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mark Noten <>
Subject JXPath 1.2: set same value for multiple properties
Date Wed, 18 Jul 2007 12:48:05 GMT
Hi all,

is there a way to set the value on every property that matches an XPath
to a new value by using the method setValue(xpath, newValue) on an
JXPathContext instance?

For example:

boolean overwritable = true;
String newValue = "PY";
String xpath =
Object currentValue = context.getValue(xpath);
if (overwritable || StringUtils.isBlank(String.valueOf(currentValue))) {
    context.setValue(xpath, newValue);

The result is that only *the first found* 'entityIdentifierCode'
property will get the new value 'PY'. All the other
'entityIdentifierCode' properties in the object structure still have
their old value 'PR'.

The result of calling executing "context.setValue(xpath, newValue)"
statement should be equivalent to the code below:

    // Overwrite the N101 value 'PR' with the default value 'PY' on the
    // expected output 'AscX12_820_831' structure object
    List transactionSets = expectedOutputFormat.getFunctionalGroup820()
    for (Iterator it = transactionSets.listIterator(); it.hasNext();) {
        TransactionSet820 transactionSet = (TransactionSet820);
        List loopList = transactionSet.getLoopList();
        for (Iterator loopIt = loopList.listIterator(); loopIt.hasNext();) {
        Loop loop = (Loop);
        SegmentN1 segmentN1 = loop.getSegmentN1();
        if ("PR".equals(segmentN1.getEntityIdentifierCode()))
            try {
            } catch (ValidationException exc) {}

The "context.getValue(xpath)" statement gives back a single result equal
to the String "PR". I think there must be an error in my XPath
expression because I saw in the source support for setting a value for a

Any help is appreciated...

Kind regards,


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message