Gossamer Forum
Home : General : Perl Programming :

XML and perl

Quote Reply
XML and perl
Hi all,

A little help please

I have .cs file in XML

See below.

How do I get this to work in perl.
As I am a not familiar with XML I need to either change this file to perl or get it to run on Apache server in order to extract the data from the client Mysql database.

Any help appreciated

Thanks
*************************
Code:
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;

namespace SupplierPubUsageExample
{
class Program
{
static private string sUsername = "username";
static string sPassword = "password";
static int iLastRefNum = 0;
//static string wsUrl = "http://localhost:3906/domain/SupplierPub.asmx";
static string wsUrl = "http://www.domain.co.uk/1stChoiceServices/SupplierPub.asmx";


static void Main(string[] args)
{
//GetOrders(sUsername, sPassword, iLastRefNum);
MakeQuote(sUsername, sPassword);
}

static void GetOrders(string Username, string Password, int LastRefNum)
{
string ReturnString = "";
wsSupplier.SupplierPub ws = new wsSupplier.SupplierPub();
ws.Url = wsUrl;

ReturnString = ws.GetOrders(Username, Password, LastRefNum);
List<OrderDetails> lOrders = ParseGetOrdersResult(ReturnString);
}

private class PartDetails
{
public string pid;
public string pdsc;
public string pcmt;

public PartDetails(string pid, string pdsc, string pcmt)
{
this.pid = pid;
this.pdsc = pdsc;
this.pcmt = pcmt;
}
}

private class OrderDetails
{
public string rfno;
public string date;
public string cdes;
public string cmak;
public string cran;
public string cyer;
public string cbdy;
public string cbdt;
public string cgbx;
public string cfue;
public string cvin;
public string cenn;
public string cccs;
public string cclr;
public string creg;
public string unam;
public string uloc;
public string upos;
public string uphn;
public string umob;
public string ueml;

public List<PartDetails> lParts = new List<PartDetails>();
}

static List<OrderDetails> ParseGetOrdersResult(string ReturnString)
{
List<OrderDetails> lRet = new List<OrderDetails>();
XmlDocument document = new XmlDocument();
try
{
ReturnString = ReturnString.Replace("&", "&amp;");
document.LoadXml(ReturnString);
XmlNode root = document.DocumentElement;
XmlNodeList xmlOrders = root.SelectNodes("descendant::rq");
foreach (XmlNode order in xmlOrders)
{
lRet.Add(ParseOrderXML(order));
}
}
catch (Exception ex)
{
string str = ex.Message;
//return error
}

return lRet;
}

static OrderDetails ParseOrderXML(XmlNode xmlOrder)
{
OrderDetails oRet = new OrderDetails();

XmlNode xmlOrDet01 = xmlOrder.SelectSingleNode("descendant::rfno");
oRet.rfno = xmlOrDet01.InnerText;
XmlNode xmlOrDet02 = xmlOrder.SelectSingleNode("descendant::date");
oRet.date = xmlOrDet02.InnerText;
XmlNode xmlOrDet03 = xmlOrder.SelectSingleNode("descendant::cdes");
oRet.cdes = xmlOrDet03.InnerText;
XmlNode xmlOrDet04 = xmlOrder.SelectSingleNode("descendant::cmak");
oRet.cmak = xmlOrDet04.InnerText;
XmlNode xmlOrDet05 = xmlOrder.SelectSingleNode("descendant::cran");
oRet.cran = xmlOrDet05.InnerText;
XmlNode xmlOrDet06 = xmlOrder.SelectSingleNode("descendant::cyer");
oRet.cyer = xmlOrDet06.InnerText;
XmlNode xmlOrDet07 = xmlOrder.SelectSingleNode("descendant::cbdy");
oRet.cbdy = xmlOrDet07.InnerText;
XmlNode xmlOrDet08 = xmlOrder.SelectSingleNode("descendant::cbdt");
oRet.cbdt = xmlOrDet08.InnerText;
XmlNode xmlOrDet09 = xmlOrder.SelectSingleNode("descendant::cgbx");
oRet.cgbx = xmlOrDet09.InnerText;
XmlNode xmlOrDet10 = xmlOrder.SelectSingleNode("descendant::cfue");
oRet.cfue = xmlOrDet10.InnerText;
XmlNode xmlOrDet11 = xmlOrder.SelectSingleNode("descendant::cvin");
oRet.cvin = xmlOrDet11.InnerText;
XmlNode xmlOrDet12 = xmlOrder.SelectSingleNode("descendant::cenn");
oRet.cenn = xmlOrDet12.InnerText;
XmlNode xmlOrDet13 = xmlOrder.SelectSingleNode("descendant::cccs");
oRet.cccs = xmlOrDet13.InnerText;
XmlNode xmlOrDet14 = xmlOrder.SelectSingleNode("descendant::cclr");
oRet.cclr = xmlOrDet14.InnerText;
XmlNode xmlOrDet15 = xmlOrder.SelectSingleNode("descendant::creg");
oRet.creg = xmlOrDet15.InnerText;
XmlNode xmlOrDet16 = xmlOrder.SelectSingleNode("descendant::unam");
oRet.unam = xmlOrDet16.InnerText;
XmlNode xmlOrDet17 = xmlOrder.SelectSingleNode("descendant::uloc");
oRet.uloc = xmlOrDet17.InnerText;
XmlNode xmlOrDet18 = xmlOrder.SelectSingleNode("descendant::upos");
oRet.upos = xmlOrDet18.InnerText;
XmlNode xmlOrDet19 = xmlOrder.SelectSingleNode("descendant::uphn");
oRet.uphn = xmlOrDet19.InnerText;
XmlNode xmlOrDet20 = xmlOrder.SelectSingleNode("descendant::umob");
oRet.umob = xmlOrDet20.InnerText;
XmlNode xmlOrDet21 = xmlOrder.SelectSingleNode("descendant::ueml");
oRet.ueml = xmlOrDet21.InnerText;

XmlNodeList xmlParts = xmlOrder.SelectNodes("descendant::part");
foreach (XmlNode xmlPart in xmlParts)
{
XmlNode xmlOrDet22 = xmlOrder.SelectSingleNode("descendant::pid");
XmlNode xmlOrDet23 = xmlOrder.SelectSingleNode("descendant::pdsc");
XmlNode xmlOrDet24 = xmlOrder.SelectSingleNode("descendant::pcmt");
oRet.lParts.Add(new PartDetails(xmlOrDet22.InnerText, xmlOrDet23.InnerText, xmlOrDet24.InnerText));
}

return oRet;
}

static void MakeQuote(string Username, string Password)
{
string request = "<quot rfno=\"2068421\" delp=\"840\" pcmt=\"my comment\" ccmt=\"comment for user\"><part pid=\"2663327\" gtm=\"3\" cnd=\"2\" prce=\"1200\" /></quot>";
string ReturnString = "";
wsSupplier.SupplierPub ws = new wsSupplier.SupplierPub();
ws.Url = wsUrl; ;
ReturnString = ws.MakeQuote(Username, Password, request);
}
}
}

Last edited by:

Andy: Nov 2, 2010, 12:32 PM
Quote Reply
Re: [Norvin1] XML and perl In reply to
Hi all

Regarding this matter below.
can anyone deal with this for me on a paid a basis.

I need to get this data from a remote server to a web form for parsing.

Hope to hear soon

Norvin
Quote Reply
Re: [Norvin1] XML and perl In reply to
As i have no idea of the .cs file or how it is executed could someone point me in the right direction to get this done or more resources on the matter

cheers getting desperate to finish this

Norvin
Quote Reply
Re: [Norvin1] XML and perl In reply to
Hi,

What are you trying to do? Extract data from the mySQL DB, and print it out as XML?

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates
Quote Reply
Re: [Andy] XML and perl In reply to
Hi thanks

Ok the customer fills in a form on say my site and has a code from another remote database, that contains all his purchase details

he complets the form entering the code given

submits the form and using the .cs supplied buy the other company that has his details the .cs collects the data and displays the details in the form on my site.
he the proceeds to checkout.

The .cs is supplied with password and user name to access the remote site, in order to collect the data.

so

customer enter my site > enters code> (.cs supplied) collects data from remote server> displays on my site> proceeds to checkout on my site.

The code ( WWMOT4563) is given to him by the remote server when he was there looking to make a purchase. as they don't stock the item he comes to my site
the .cs was given to me by the remote server admin, to access their database complete with password (omitted).

eg2

Customer wants a part for a car, say a wiper motor. He requests that from a site the holds data of companies that have that wiper motor, in stock.

He is given a code for the part.

He then access another site, say my site enters the code, the .cs collects the data from the remote Mysql server (First site he went to)

the data appears on my sites form he then enters what is missing say name delivery address etc and checks out.

The .cs script just accesses the remote server and collects the date for me to parse using perl.

Hope that help

Cheers for the reply

Norvin
Quote Reply
Re: [Norvin1] XML and perl In reply to
It is becoming clearer.

In a few words


collect the data from a remote server database> and process it on my site

Perl can do that just not sure of the procedures in the .cs before i spend hours on it


Norvin
Quote Reply
Re: [Norvin1] XML and perl In reply to
Hi,

Ok, so it sounds like you are retrieving the data ok already using the .cs script?

What does the data look like? If you already have it in XML format, it should be very simple to convert/use it in Perl, using something like XML::Simple

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates
Quote Reply
Re: [Andy] XML and perl In reply to
Hi,
Sorry for the ignorance but i have no idea how to install or execute the .cs script

how do i install and compile it to run?

Cheers for your time

norvin
Quote Reply
Re: [Norvin1] XML and perl In reply to
Hi,

Ah ok - I thought it sounds like you already had that up and running.

I'm afraid I've never used .cs scripts - In fact, I'm not even sure what language it is?

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates
Quote Reply
Re: [Andy] XML and perl In reply to
Cheers Andy same problem

On shell prompt i have tried

cc scgi.cs

output is

cgi-bin]# cc Program.cs
/usr/bin/ld:Program.cs: file format not recognized; treating as linker script
/usr/bin/ld:Program.cs:1: syntax error
collect2: ld returned 1 exit status

How to compile this .cs

and then deal with the data

Cheers any help huh?
Quote Reply
Re: [Norvin1] XML and perl In reply to
Hi,

Mmm, not really sure

You could try asking at tek-tips.com (in the "Apache" forum) ... hopefully someone will know what the extension is, how to compile it, and how to run it.

Hope that helps.

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates
Quote Reply
Re: [Norvin1] XML and perl In reply to
Hi


I am getting closer to solving this

The .cs file was just an example

This is the SOAP version

I need to either get it to work or convert to perl
As it is it gives errors.
I nee to query a remote asmx database and get the results


Any one can do this please

Norvin

#!/usr/local/bin/perl
use SOAP::Lite;
POST /1stChoiceServices/SupplierPub.asmx HTTP/1.1
Host: 94.236.88.2
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "1stChoice/GetOrders"

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<GetOrders xmlns="1stChoice">
<Username>string</Username>
<Password>string</Password>
<LastRef>int</LastRef>
</GetOrders>
</soap:Body>
</soap:Envelope>
Quote Reply
Re: [Norvin1] XML and perl In reply to
Hi,

Thats not valid syntax =)

Check out this link:

http://www.google.co.uk/...;fp=dc6e1eca89c74660

There is also quite a lot of documentation here: http://search.cpan.org/...ite/lib/SOAP/Lite.pm

Once you have the data, just pass the response into XML::Simple::XMLin() , and then to see the output of the records, do something like:

Code:
use Data::Dumper;
print Dumper($ref);

..so you can see the strucutre of the data.

If you would prefer me to try this as a custom job, please let me know (you can email or PM me)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates