Having problems with your account or logging in?
A lot of changes are happening in the community right now. Some may affect you. READ MORE HERE
Micro Focus Expert
Micro Focus Expert

CDATA - what is it, how to handle it

I recently had a follower send me a private post asking about how does HPE SV handle CDATA as they are trying to manipulate the values they are passing in the CDATA field.


First, we should define what CDATA is.  CDATA stands for Character Data and is a way of passing a string between client and server.  But wait, I am passing an xml in CDATA.  Yes, you maybe passing what appears to be an XML but in reality, you are passing a string and you have instructed the client and server explicitly to NOT treat it as an XML.  As such, HPE SV will store it as a string since it has no other choice.


So how can you work with this in HPE SV?

  • Create your own custom function f(x) - How to Define Rule Functions
  • Scripted rule

 In the example I share here, I elected to use a C# scripted rule.  To do this, you will need to include the System.Xml assembly for HPE SV to use by modifying the <HPE SV>\bin\Config\scripted-rule-context.xml file and adding it.


  <object id="DotNetServiceOperationRuleNetRuleExecutor" type="HP.SV.Runtime.Simulation.DataSimulator.ServiceOperationRule.CSharp.DotNetServiceOperationRuleNetRuleExecutor, HP.SV.Runtime.Simulation.DataSimulator" autowire="byType">
    <constructor-arg index="0" ref="DataSimulator" />
    <property name="ReferenceAssemblies" value="System,System.Core,System.Xml" />
    <property name="DynamicAssemblyCompilation" value="Release" />  <!-- Release, Debug -->
    <property name="ScriptCompilation" value="Release" />  <!-- Release, Debug -->


I took a short cut and based the wsdl off the MemberAccounts service and just worked on the getMemberPlan operation.


You will need to provide your own client (UFT, SoapUI, FireFox SOA Client) to query the attached project (CDATA.zip) if you wish to actually send requests.  I have also include the modified wsdl file for what I did.


1 Reply
Micro Focus Expert
Micro Focus Expert

Re: CDATA - what is it, how to handle it

Here is an update on what I think would be even easier.  Make use of System.Xml.Linq to manipulate as building and iterating seems easier.  Note: you will need to add System.Xml.Linq to the scripted-rule-context.xml file

using System;
using System.Xml;
using System.Xml.Linq;
using HP.SV.DotNetRuleApi;
using HP.SV.CSharp;

namespace HP.SV{
    public class CSharpRule{
        public static void Execute(HpsvRootObject hpsv){
            // Strip the CDATA from the value passed.  There are many ways you could do this
            // this was just a quick method of doing it to load it in for processing
            var txt = hpsv.Request.getMemberPlan.myCdataIn.Substring(9);
            txt = txt.Substring (0, txt.Length-3);

            XDocument rqstXmlDocRoot = XDocument.Parse(txt);
            txt = hpsv.Response.getMemberPlanResponse.getMemberPlanResult.myCdataOut.Substring(9);
            txt = txt.Substring(0, txt.Length-3);
            XDocument rspXmlDocRoot = XDocument.Parse(txt);

            // Place the value back in to CDATA format
            hpsv.Response.getMemberPlanResponse.getMemberPlanResult.myCdataOut =


Here are some reference site I viewed when looking in to this:






Final note: Yes, I realize I essentially hard coded the node names in and it would be more elegant and flexible if I would have created more complex selects and iterate through the values until selecting the one I wanted.  However, this is just an example on how to approach it and was not to be a final solution to add to a tool kit.

Good luck.

The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.