List Info

Thread: How to edit data in a specific part of an XMLObject




How to edit data in a specific part of an XMLObject
country flaguser name
United States
2007-08-14 14:52:32
I have and XMLObject node I find by using an XPath expression in my XMLObject root element (XMLINIDocument). It finds this XMLObject (there is only one instance) but I want to replace it with another one. How do I do this?
 
** XML DOCUMENT **
 
<XMLINI>
 &nbsp;<CONFIG>
 &nbsp;  <SERVICES>
 &nbsp; &nbsp;  <SERVICE>
 &nbsp; &nbsp; &nbsp;  <WIPKEYS>
 &nbsp; &nbsp; &nbsp; &nbsp;  I WANT TO REPLACE THIS DATA
 &nbsp; &nbsp; &nbsp;  </WIPKEYS>
.....
</XMLINI>
 
 
** CODE **
 
  // Load entire XML document
  XMLINIDocument config = XMLINIDocument.Factory.parse(editor.getText(), validateOptions);
  // Create xpath to the node we wish to replace
  String wipQueryExpression = "declare namespace xq='http://skywire.com/ccm/global';" +
 &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp;  "$this/xq:XMLINI/xq:CONFIG/xq:SERVICES/xq:SERVICE/xq:WIPKEYS";
 
 &nbsp;// XMLObject found through XPath.&nbsp; This is the one I want to replace with the new one.
 ; WIPKEYSDocument.WIPKEYS[] wipkeys = (WIPKEYSDocument.WIPKEYS[]) config.selectPath(wipQueryExpression);
  // Got XML data from server and loaded it into a WIPKEYSDocument and wish to replace the wipkeys above with this one
  WIPKEYSDocument keys = WIPKEYSDocument.Factory.parse(serverData, validateOptions);
  // This kind of substitution does not work
  wipkeys[0] = keys.getWIPKEYS();
 
  // Then I save it at the end
  config.save(new File("war/WEB-INF/xml/global.xml"));
 
 
Any ideas?
Thx,
Bob


Moody friends. Drama queens. Your life? Nope! - their life, your story.
Play Sims Stories at Yahoo! Games.
[1]

about | contact  Other archives ( Real Estate discussion Medical topics )