Raja Islam's Technical blog

How to parse XML and Fetch data

var input1 = TheApplication().NewPropertySet();
var output1 = TheApplication().NewPropertySet();
var svc = TheApplication().GetService(“Transcode Service”);
input1.SetProperty(“ConversionMode”,”StringToEncoding”);
input1.SetProperty(“TargetEncoding”,”UTF-8″);
//this is the string XML
input1.SetValue(“<?xml version=\”1.0\” encoding=\”UTF-8\”?>” +
“<Result><SiteRoot>http://mySite.net</SiteRoot><SiteName>mySite</SiteName>” +
“<JobMatchesLink>http://mySite.net/login.asp</JobMatchesLink>” +
“<JobMatches>25</JobMatches><ONET>15-222.00</ONET><Password>admin</Password>” +
“<Username>admin</Username><SSN>999999999</SSN></Result>”);
svc.InvokeMethod(“Convert”, input1, output1);
//assign the UTF-8 converted output to the input of the XML Converter BS
var inputx = output1;
var outputx = TheApplication().NewPropertySet();
var svc = TheApplicationication().GetService(“XML Converter”);
//TheApplication().GetBusObject(“Contact”).GetBusComp(“Contact”).SetFieldValue(“lastname”,”123″);
svc.InvokeMethod(“XMLToPropSet”, inputx, outputx);
/*in the BS simulator you will see the Result with all the XML into a
property set hierarchy and you can access these child properties as I
showed you in my previous code.*/
Outputs.AddChild(outputx);
COMCreateObject(“WScript.Shell”).PopUp(outputx.GetChild(6).GetValue());

I used this code in siebel Business Service.  It will display value from XML in popup  which is “admin” because it is sixth in hierarchy.  Below is the code to get any value from XML string.

var input1 = TheApplication().NewPropertySet();

var output1 = TheApplication().NewPropertySet();

var svc = TheApplication().GetService(“Transcode Service”);

input1.SetProperty(“ConversionMode”,”StringToEncoding”);

input1.SetProperty(“TargetEncoding”,”UTF-8″);

//this is the string XML

input1.SetValue(“<?xml version=\”1.0\” encoding=\”UTF-8\”?>” +

“<Result><SiteRoot>http://mySite.net</SiteRoot><SiteName>mySite</SiteName>” +

“<JobMatchesLink>http://mySite.net/login.asp</JobMatchesLink>” +

“<JobMatches>25</JobMatches><ONET>15-222.00</ONET><Password>admin</Password>” +

“<Username>admin</Username><SSN>999999999</SSN></Result>”);

svc.InvokeMethod(“Convert”, input1, output1);

//assign the UTF-8 converted output to the input of the XML Converter BS

var inputx = output1;

var outputx = TheApplication().NewPropertySet();

var svc = TheApplicationication().GetService(“XML Converter”);

//TheApplication().GetBusObject(“Contact”).GetBusComp(“Contact”).SetFieldValue(“lastname”,”123″);

svc.InvokeMethod(“XMLToPropSet”, inputx, outputx);

Outputs.AddChild(outputx);

COMCreateObject(“WScript.Shell”).PopUp(outputx.GetChild(6).GetValue());// It will output “admin”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.