Hi
I am writing a utility that allows one to update portions of an xml document using xpath expressions. i.e. update(String xpathString , String newValue)
 
For example, lets say the document is:
 
<addressBook>
      <address>
           <firstName>John</firstName>
           <surname>Smith</surname>
           <email>[EMAIL PROTECTED]</email>
           <tel type = "work">234-123-222</tel>
      </address> 
 </addressBook>
 
Suppose u wanted to changed John's surname to 'Taylor'. U would call a method in my utility class as:
 
  utilObj.update( "/addressBook/address[child::firstName[text()='John']]/surname"  , "Taylor" );
 
So far so good. But i want behaviour that defaults updates to inserts if the element is not found.
e.g. If i want to add a middleName for John, i want to be able to say:
 
  utilObj.update( "/addressBook/address[child::firstName[text()='John']]/middleName"  , "W" );
 
now xpath.execute(...) would return an empty list as 'middleName' is not present. At this point, I want to get a handle to the last node that was found , which would be the 'address' element in this case (so that i can add a child for address). How do I achieve this? i.e. how do I tell xpath to return the last node found while traversing the _expression_?
 
I tried NodeCallback but it never seems to get called.
 
thanks in anticipation
-sriram

Reply via email to