cancel
Showing results for 
Search instead for 
Did you mean: 

xmldecode

Former Member
0 Kudos

Hi all,

In a transaction, the input is string. the string contains the encoded xml file.( The xml is xMII XML Format)

Now I want to decode the xml file and assign it to local property of xml type.

In the link editor, While evaluating the value it shows the xml file.While executing the transaction, it shows no error. But I could not get any output.

I have tried with the xml saver. It is not working.

Any inputs...???

Regards,

Kishore

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Kishore,

I was experiencing a similar issue, so I wrote a custom action block.

See below for the code...

import com.lighthammer.xacute.actions.ActionReflectionBase;

import com.lighthammer.xacute.core.ILog;

import com.lighthammer.xacute.core.Transaction;

import com.lighthammer.xml.XMLDataType;

import javax.xml.parsers.DocumentBuilder;

import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;

public class TextToXml extends ActionReflectionBase

{

public TextToXml()

{

_texttoparse = "";

}

public String getTextToParse()

{

return _texttoparse;

}

public void setTextToParse(String s)

{

_texttoparse = s;

}

public XMLDataType getContent()

{

return _xmlcontent;

}

public void setContent(XMLDataType s)

{

_xmlcontent = s;

}

public String GetIconPath()

{

return "/com/companyx/xacute/actions/resources/icons/XMLParser.png";

}

public void Invoke(Transaction transaction, ILog ilog)

{

_xmlcontent = new XMLDataType();

try

{

String xmlContent = xmlDecode(_texttoparse);

DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();

DocumentBuilder builder = domFactory.newDocumentBuilder();

Document doc = builder.parse(new org.xml.sax.InputSource(new java.io.StringReader(xmlContent)));

_xmlcontent = new XMLDataType(doc);

_success = true;

}

catch(Exception ex)

{

_success = false;

}

}

private String xmlDecode(String strIn)

{

strIn = stringReplace(strIn, "&", "&");

strIn = stringReplace(strIn, "&lt;", "<");

strIn = stringReplace(strIn, "&gt;", ">");

strIn = stringReplace(strIn, "&apos;", "'");

strIn = stringReplace(strIn, "&quot;", "\"");

return strIn;

}

private String stringReplace(String strSource, String strSearch, String strReplace)

{

StringBuffer sb = new StringBuffer();

int nLastPos = 0;

for(int nPos = strSource.indexOf(strSearch, nLastPos); nPos >= 0; nPos = strSource.indexOf(strSearch, nLastPos))

{

sb.append(strSource.substring(nLastPos, nPos));

sb.append(strReplace);

nLastPos = nPos + strSearch.length();

}

sb.append(strSource.substring(nLastPos, strSource.length()));

return sb.toString();

}

private String _texttoparse;

private XMLDataType _xmlcontent;

}

Hope this helps.

Regards,

Matt Tuohy

Former Member
0 Kudos

Hi Matt,

How this block is linked into BLS?

Where I can write the same code?

Guide me on this....

Regards,

Kishore kumar P.S.

Former Member
0 Kudos

Hi Matthew

I have a doubt here where to save MyAction.java

i am getting following errors

C:\j2sdk1.4.2_11\bin>javac MyAction.java

MyAction.java:8: class TextToXml is public, should be declared in a file named T

extToXml.java

public class TextToXml extends ActionReflectionBase {

^

MyAction.java:1: package com.lighthammer.xacute.actions does not exist

import com.lighthammer.xacute.actions.ActionReflectionBase;

^

MyAction.java:2: package com.lighthammer.xacute.core does not exist

import com.lighthammer.xacute.core.ILog; import com.lighthammer.xacute.core.Tran

saction;

^

MyAction.java:2: package com.lighthammer.xacute.core does not exist

import com.lighthammer.xacute.core.ILog; import com.lighthammer.xacute.core.Tran

saction;

^

MyAction.java:3: package com.lighthammer.xml does not exist

import com.lighthammer.xml.XMLDataType;

^

MyAction.java:8: cannot resolve symbol

symbol : class ActionReflectionBase

location: class TextToXml

public class TextToXml extends ActionReflectionBase {

^

MyAction.java:24: cannot resolve symbol

symbol : class XMLDataType

location: class TextToXml

public XMLDataType getContent()

^

MyAction.java:29: cannot resolve symbol

symbol : class XMLDataType

location: class TextToXml

public void setContent(XMLDataType s)

^

MyAction.java:39: cannot resolve symbol

symbol : class Transaction

location: class TextToXml

public void Invoke(Transaction transaction, ILog ilog)

^

MyAction.java:39: cannot resolve symbol

symbol : class ILog

location: class TextToXml

public void Invoke(Transaction transaction, ILog ilog)

^

MyAction.java:83: cannot resolve symbol

symbol : class XMLDataType

location: class TextToXml

private XMLDataType _xmlcontent;

^

MyAction.java:41: cannot resolve symbol

symbol : class XMLDataType

location: class TextToXml

_xmlcontent = new XMLDataType();

^

MyAction.java:48: cannot resolve symbol

symbol : class XMLDataType

location: class TextToXml

_xmlcontent = new XMLDataType(doc);

^

MyAction.java:49: cannot resolve symbol

symbol : variable _success

location: class TextToXml

_success = true;

^

MyAction.java:53: cannot resolve symbol

symbol : variable _success

location: class TextToXml

_success = false;

Regards Namita

Message was edited by:

Namita Tripathi

Former Member
0 Kudos

Namita,

The document i sent you is a generic 'how to guide' on creating action blocks.

The names of the classes and files in the document are my examples for the purpose of the document.

When writing the TextToXml action block, you need to use the string TextToXml whereever the MyAction string appears in the document. Including the name of the java file.

I would also suggest giving a meaningful name to the JAR file and replacing 'companyx' with your vendor name.

Regards,

Matt Tuohy

Former Member
0 Kudos

Hi Matthew Tuohy,

I am also looking for a help to create the custom action block, in xMII. It would be of great help if you share the document on " guide to create custom action block"

My e-mail ID: vishal.jadhav@tcs.com

Thanks for your time.

Regards

Vishal

Former Member
0 Kudos

Hi Matthew..

I want to create CC: option while mailing in BLS (XMII 11.0).

Since there is no already built in option, i am trying to create a custom action block for it.

I just got the hint..it can be achieved via creating own custom block...

Can you help me in creating custom action block?

Any material/ idea/ link ... anything wld be of great help...

Thanking you in anticipation..

Ruchir

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi, all.

A word of (strong) caution. Writing and adding custom action blocks is not something to be taken lightly. This code will run inside the BLS engine and can therefore cause significant problems if it is not written correctly.

This will be more "officially" supported with an SDK and deployment model in version 12.0, but I would not count on any official technical support for custom action blocks in 11.5. You'll have to depend on peer support here on SDN and you must accept all risk for any problems you might cause with your xMII installation.

- Rick

Former Member
0 Kudos

Hi all,

Thanks for the inputs.

Regards,

Kishore kumar P.S.

Former Member
0 Kudos

Kishore,

I have written a white paper titled <b>Writing custom Action Blocks for xMII 11.5</b>

I cannot find a decent way to publish it in the forum...

I can email it to you if you wish?

Regards,

Matt Tuohy

Former Member
0 Kudos

Hi Matthew,

Mail this to pskishkumar@yahoo.co.in

It will help us a lot.

Regards,

Kishore

Former Member
0 Kudos

Can you send me this document as well? bjhoffma@gmail.com

I am working on converting custom action blocks from version 11.0 to 11.5 and I'm most interested in where the files need to be place on the xMII server. Thanks!

Former Member
0 Kudos

Hi Brett....

I want to create CC: option while mailing in BLS (XMII 11.0).

Since there is no already built in option, i am trying to create a custom action block for it.

I just got the hint..it can be achieved via creating own custom block...

Can you help me in creating custom action block?

Any material/ idea/ link ... anything wld be of great help...

Thanking you in anticipation..

Ruchir

abesh
Contributor
0 Kudos

Hi Kishore,

Could you please send the Transaction to my Email ID and let me have a look at it ?

Former Member
0 Kudos

Hi Abesh,

<?xml version="1.0" encoding="UTF-8"?><Rowsets xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<Rowset>

<Columns>

<Column Description="" MaxRange="0" MinRange="0" Name="VALUE" SQLDataType="1" SourceColumn="VALUE"/>

</Columns>

<Row>

<VALUE>0012</VALUE>

</Row>

<Row>

<VALUE>0012</VALUE>

</Row>

</Rowset>

</Rowsets>

This xml is encoded as a string.

I am using an assignment action to assign it to local proerty of xml type.

The expression used in the assignment action is

Local.xml----> xmldecode(Transaction.string)

The output structure after decoding this xml looks like the same xml.

I hope this helps you.

Regards,

Kishore

Former Member
0 Kudos

Hi.

You should be able to change the transaction input to type "XML" and xMII will automatically parse it into an XML document.

- Rick

Former Member
0 Kudos

Hi Rick,

If Input type is changed as xml type, the transaction can't be exposed as a web service. Thats why Input type is changed as string.

A string contains the encoded xml. By using xmldecode(String), it is converted into xml type. Now I have a xml. It has to be assigned to a xml type property. But it is not happening. Whenever the transaction is executed, it is not showing any error.

I hope this helps you to understand my problem in better way.

Regards,

Kishore

Former Member
0 Kudos

Hi all,

The problem here is, the output of xmldecode is in string type. when it is assigned to xml type, the transaction is not running.

The above method won't work.

The ultimate aim is

1. To get a string which contains the whole xml file.

2. Change it to xml type.

How this can be acheived?

any inputs appreciated.......

Regards,

Kishore

Former Member
0 Kudos

I understand. The correct way to do this is with the StringToXml action, but there is a bug with this action that is not fixed until 11.5 SR3.

A workaround is to save the string content to a temporary file with the TextSaver action, load the same file using the XmlLoader action, and then delete the file with the DeleteFile action. This will work.

Also, you shouldn't need to xmldecode the string - this should automatically happen. Try it without the xmldecode (and the above technique) and see if it works.

Best regards,

Rick

Former Member
0 Kudos

Hi,

This solution works fine. But I have to save the file and delete it.

Is any other option there?

Regards,

Kishore

Former Member
0 Kudos

Hi, Kishore.

SAP xMII 11.5 SR3 should be available shortly, which includes a fix to the StringToXml action. This action is precisely what you need. You pass a string into the action, and an Xml object is the output.

Best regards,

Rick