The problem is getting access to the parent. If you look at the XML below,
there are many <SERVICE> elements with only one with a <WIPKEYS>. How do I get
access to the <SERVICE> or SERVICEDocument to replace the specific (and only)
<WIPKEYS>.
Can I see some code? What you guys are describing sounds like what I've tried
that is not working.
XMLINIDocument config =
XMLINIDocument.Factory.parse(editor.getText(), validateOptions);
String wipQueryExpression = "declare namespace
xq='http://skywire.com/ccm/global';" +
"$this/xq:XMLINI/xq:CONFIG/xq:SERVICES/xq:SERVICE/xq:WIPKEYS";
// THIS GIVE ME THE CORRECT DATA TO REPLACE BUT I GUESS
THIS IS A COPY????
WIPKEYSDocument.WIPKEYS[] wipkeys =
((WIPKEYSDocument[].WIPKEYS) config.selectPath(wipQueryExpression));
// LOAD NEW DATA INTO AN XML BEAN OBJECT
WIPKEYSDocument keys =
WIPKEYSDocument.Factory.parse(serverData, validateOptions);
// IF THIS IS A COPY, IT WONT UPDATE THE ROOT 'config'
OBJECT ABOVE....and it doesn't
wipkeys[0] = keys.getWIPKEYS();
As for XMLCursor;
// THIS IS THE SAME XPATH YET RETURNS THE ROOT XMLINI
NODE?!?!
XmlCursor itemCursor = config.newCursor();
itemCursor.selectPath(wipQueryExpression);
Thx,
bob
----- Original Message ----
From: Jacob Danner <[EMAIL PROTECTED]>
To: [email protected]
Sent: Wednesday, August 15, 2007 5:15:35 PM
Subject: Re: 2nd Post. Help! Search and Replace...Re: How to edit data in a
specific part of an XMLObject
If you use the other method Cezar mentioned
parent.setWIPKEYS(keys.getWIPKEYS())
you can replace the entire WIPKEYS array.
Otherwise if you only want to replace one at a time there are some
methods for that too like insert, etc.
-Jacob Danner
On 8/15/07, bob bob <[EMAIL PROTECTED]> wrote:
>
> Thanks.
> But now the problem is, how do I get a reference to the parent? I thought I
> was getting a reference with selectPath() but apparently not. The XML file
> is HUGE with tons of elements, data, etc. There is only one instance of
> WIPKEYS so I would just like to replace what's there.
> If I get a reference to WIPKEYS and call what you have below;
> wipkeys[0].set(keys.getWIPKEYS()); it will just replace that copy and not
> the WIPKEYS section in the root of the main XML doc (XMLINI).
> Thanks,
> bob
>
>
> ----- Original Message ----
> From: Cezar Andrei <[EMAIL PROTECTED]>
> To: [email protected]
> Sent: Wednesday, August 15, 2007 3:40:33 PM
> Subject: RE: 2nd Post. Help! Search and Replace...Re: How to edit data in a
> specific part of an XMLObject
>
>
>
>
> Bob,
>
>
>
> The wipkeys array returned from selectPath() method is just a copy, it's not
> a live object in XMLBeans structures, so modifying it will not change the
> original document.
>
>
>
> You should call wipkeys[0].set(keys.getWIPKEYS()); or locate it's parent and
> call parent.setWIPKEYS(keys.getWIPKEYS()) .
>
>
>
> Cezar
>
>
>
>
> ________________________________
>
>
> From: bob bob [mailto:[EMAIL PROTECTED]
> Sent: Wednesday, August 15, 2007 1:25 PM
> To: [email protected]
> Subject: 2nd Post. Help! Search and Replace...Re: How to edit data in a
> specific part of an XMLObject
>
>
>
>
>
> Anyone?
>
>
> Basically I want a search and replace. I can grab the XMLObject
> (WIPKEYSDocument) but can't replace it with another
>
>
> WIPKEYSDocument.
> Please?! Anyone?
>
>
>
>
>
>
> ----- Original Message ----
> From: bob bob <[EMAIL PROTECTED]>
> To: [email protected]
> Sent: Tuesday, August 14, 2007 3:52:32 PM
> Subject: How to edit data in a specific part of an XMLObject
>
>
>
> 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>
>
>
> <CONFIG>
>
>
> <SERVICES>
>
>
> <SERVICE>
>
>
> <WIPKEYS>
>
>
> I WANT TO REPLACE THIS DATA
>
>
> </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';"; +
>
> "$this/xq:XMLINI/xq:CONFIG/xq:SERVICES/xq:SERVICE/xq:WIPKEYS";
>
>
>
>
>
> // XMLObject found through XPath. 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.
>
>
>
>
>
> ________________________________
>
>
> Shape Yahoo! in your own image. Join our Network Research Panel today!
> Notice: This email message, together with any attachments, may contain
> information of BEA Systems, Inc., its subsidiaries and affiliated entities,
> that may be confidential, proprietary, copyrighted and/or legally
> privileged, and is intended solely for the use of the individual or entity
> named in this message. If you are not the intended recipient, and have
> received this message in error, please immediately return this by email and
> then delete it.
>
>
> ________________________________
> Ready for the edge of your seat? Check out tonight's top picks on Yahoo! TV.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
____________________________________________________________________________________Ready
for the edge of your seat?
Check out tonight's top picks on Yahoo! TV.
http://tv.yahoo.com/