Forum Discussion

ITAbteilung's avatar
ITAbteilung
Contributor
15 years ago

[Resolved]Changing textcontent of XML-Element

Dear SoapUI-Team,

I'm unable to figure out how to change the Textcontent of an XML-Element via Script. Eg i want to change <tag>xxx</tag> into <tag>yyy</tag>. I tried 2 ways:
1)

XmlHolder response = new XmlHolder( readFile( "actualResponse.xml")); //readFile is a custom method
String str = "yyy";
response.setNoteValue( "//tag", (Object)str);

doen't work, since setNoteValue wants another (?) object than a string object..

java.lang.Exception: No signature of method: com.eviware.soapui.support.XmlHolder.setNoteValue() is applicable for argument types: (java.lang.String, java.lang.String) values: [//tag, yyy] Possible solutions: setNodeValue(java.lang.String, java.lang.Object), getNodeValue(java.lang.String), getNodeValues(java.lang.String)


2)

import org.w3c.dom.*;
XmlHolder response = new XmlHolder( readFile( "actualResponse.xml")); //readFile is a custom method
Node tag = response.getDomNode( "//tag");
tag.setTextContent("yyy");

brings up the message:

java.lang.Exception: DOM Level 3 Not implemented.

I figured out where that old version of org.w3c.dom.Node Class is loaded from: it is xbean-fixed-2.4.0.jar . In xmlunit-1.2.jar should be a DOM-Level3 version of Node. It's the jar-hell! Trying to delete xbean-fixed-2.4.0.jar fails since soapUI doesn't start without that file.

Can you please tell me what to do?

Thanks in advance,
best regards,
Pat

2 Replies

  • Hi Pat,

    the XmlHolder method in your first example should be setNodeValue (ie with a d instead of a t), can you give that a try instead?

    regards,

    /Ole
    SmartBear Stockholm