Hi
I have writen a web service. this web service has a method that returnes a Table as XML format
and I need to use it as a table.
how can i use this web service as a table.
is any way to convert XML format to Table format
Thank you
pritaeas 2,194 ¯\_(ツ)_/¯ Moderator Featured Poster
Can you show the code that is returning the XML?
fayyaz 1 Junior Poster in Training
Yes of course
this is my code in Delphi prism
namespace;
interface
uses
System,
System.Web,
System.Collections,
System.Web.Services,
System.Web.Services.Protocols,
System.Data,
System.Data.SqlClient,
Microsoft.SqlServer.Server,
System.Data.SqlTypes;
type
[WebService(&Namespace := 'http://***.***.***.***')]
[WebServiceBinding(ConformsTo := WsiProfiles.BasicProfile1_1)]
Service = public class(System.Web.Services.WebService)
public
method HelloWorld: string;
method SUM(a,b:Integer):Integer;
method GetData :DataTable;
end;
implementation
[WebMethod]
method Service.HelloWorld: string;
begin
result := 'Hello World';
end;
[WebMethod]
method Service.SUM(a,b:Integer): Integer;
begin
result := a+b;
end;
[WebMethod]
method Service.GetData: DataTable;
Var
StrCon:String;
Con:SqlConnection;
DS:DataSet;
Da:SqlDataAdapter;
begin
Con:= New SqlConnection;
Con.ConnectionString:='Data Source=***.***.***.***;Initial Catalog=Data_Transform;Persist Security Info=True;User ID=*****;Password=****';
Con.Open;
Da:= new SqlDataAdapter('Select * From ADAM1_In_Data',Con);
DS:= new DataSet;
Da.Fill(DS,'Table1');
Con.Close;
result:=DS.Tables[0];
//.Rows[0].Item[7].ToString;
end;
end.
and its output in IE is attached as XML File
The attachment preview is chopped off after the first 10 KB. Please download the entire file.
<?xml version="1.0" encoding="utf-8"?>
<DataTable xmlns="http://***.***.***.***">
<xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:MainDataTable="Table1" msdata:UseCurrentLocale="true">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="Table1">
<xs:complexType>
<xs:sequence>
<xs:element name="AI" type="xs:string" minOccurs="0" />
<xs:element name="Descr" type="xs:string" minOccurs="0" />
<xs:element name="Min_I" type="xs:double" minOccurs="0" />
<xs:element name="Max_I" type="xs:double" minOccurs="0" />
<xs:element name="Min_Val" type="xs:double" minOccurs="0" />
<xs:element name="Max_Val" type="xs:double" minOccurs="0" />
<xs:element name="R" type="xs:double" minOccurs="0" />
<xs:element name="Value" type="xs:double" minOccurs="0" />
<xs:element name="LowRange" type="xs:double" minOccurs="0" />
<xs:element name="HighRange" type="xs:double" minOccurs="0" />
<xs:element name="Enable" type="xs:boolean" minOccurs="0" />
<xs:element name="unt" type="xs:string" minOccurs="0" />
<xs:element name="monitor_var" type="xs:string" minOccurs="0" />
<xs:element name="HaveSum" type="xs:boolean" minOccurs="0" />
<xs:element name="SumCoef" type="xs:double" minOccurs="0" />
<xs:element name="SumValue" type="xs:double" minOccurs="0" />
<xs:element name="SumReset" type="xs:double" minOccurs="0" />
<xs:element name="UpDownward" type="xs:string" minOccurs="0" />
<xs:element name="Sumation" type="xs:double" minOccurs="0" />
<xs:element name="Total" type="xs:int" minOccurs="0" />
<xs:element name="SaveTime" type="xs:double" minOccurs="0" />
<xs:element name="rate" type="xs:double" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
<diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
<NewDataSet xmlns="">
<Table1 diffgr:id="Table11" msdata:rowOrder="0">
<AI>00</AI>
<Descr>GRP </Descr>
<Min_I>0.004</Min_I>
<Max_I>0.02</Max_I>
<Min_Val>0</Min_Val>
<Max_Val>1000</Max_Val>
<R>120</R>
<Value>622.957</Value>
<LowRange>3</LowRange>
<HighRange>1000</HighRange>
<Enable>true</Enable>
<unt>M3 </unt>
<monitor_var>GRP </monitor_var>
<HaveSum>false</HaveSum>
<SumCoef>0.000676944444445932</SumCoef>
<SumValue>0</SumValue>
<SumReset>1</SumReset>
<UpDownward>U</UpDownward>
<Sumation>1868.871</Sumation>
<Total>3</Total>
<SaveTime>54607.817</SaveTime>
<rate>2.4370000000053551</rate>
</Table1>
<Table1 diffgr:id="Table12" msdata:rowOrder="1">
<AI>01</AI>
<Descr>RO5500 </Descr>
<Min_I>0.004</Min_I>
<Max_I>0.02</Max_I>
<Min_Val>0</Min_Val>
<Max_Val>400</Max_Val>
<R>120</R>
<Value>210.272</Value>
<LowRange>3</LowRange>
<HighRange>400</HighRange>
<Enable>true</Enable>
<unt>M3H </unt>
<monitor_var>RO5000 </monitor_var>
<HaveSum>true</HaveSum>
<SumCoef>0.00067777777777842452</SumCoef>
<SumValue>143514.14271434431</SumValue>
<SumReset>1</SumReset>
<UpDownward>U</UpDownward>
<Sumation>629.925</Sumation>
<Total>3</Total>
<SaveTime>54607.857</SaveTime>
<rate>2.4400000000023283</rate>
</Table1>
<Table1 diffgr:id="Table13" msdata:rowOrder="2">
<AI>02</AI>
<Descr>RO3000 </Descr>
<Min_I>0.004</Min_I>
<Max_I>0.02</Max_I>
<Min_Val>0</Min_Val>
<Max_Val>200</Max_Val>
<R>120</R>
<Value>73.441</Value>
<LowRange>3</LowRange>
<HighRange>400</HighRange>
<Enable>true</Enable>
<unt>M3H </unt>
<monitor_var>RO3000 </monitor_var>
<HaveSum>true</HaveSum>
<SumCoef>0.000676666666665066</SumCoef>
<SumValue>58389.128406644886</SumValue>
<SumReset>1</SumReset>
<UpDownward>U</UpDownward>
<Sumation>220.323</Sumation>
<Total>3</Total>
<SaveTime>54607.893</SaveTime>
<rate>2.4359999999942374</rate>
</Table1>
<Table1 diffgr:id="Table14" msdata:rowOrder="3">
<AI>03</AI>
<Descr>RO4000 </Descr>
<Min_I>0.004</Min_I>
<Max_I>0.02</Max_I>
<Min_Val>0</Min_Val>
<Max_Val>200</Max_Val>
<R>120.51</R>
<Value>134.235</Value>
<LowRange>0</LowRange>
<HighRange>400</HighRange>
<Enable>true</Enable>
<unt>M3H </unt>
<monitor_var>RO4000 </monitor_var>
<HaveSum>true</HaveSum>
<SumCoef>0.00067777777777640346</SumCoef>
<SumValue>83883.248779537244</SumValue>
<SumReset>1</SumReset>
<UpDownward>U</UpDownward>
<Sumation>404.163</Sumation>
<Total>3</Total>
<SaveTime>54607.933</SaveTime>
<rate>2.4399999999950523</rate>
</Table1>
<Table1 diffgr:id="Table15" msdata:rowOrder="4">
<AI>04</AI>
<Descr>MED8000 </Descr>
<Min_I>0.004</Min_I>
<Max_I>0.02</Max_I>
<Min_Val>0</Min_Val>
<Max_Val>500</Max_Val>
<R>120</R>
<Value>257.832</Value>
<LowRange>0</LowRange>
<HighRange>450</HighRange>
<Enable>true</Enable>
<unt>M3H </unt>
<monitor_var>MED </monitor_var>
<HaveSum>true</HaveSum>
<SumCoef>0.0006786111111109171</SumCoef>
<SumValue>189166.66728238764</SumValue>
<SumReset>1</SumReset>
<UpDownward>U</UpDownward>
<Sumation>773.02</Sumation>
<Total>3</Total>
<SaveTime>54607.973</SaveTime>
<rate>2.4429999999993015</rate>
</Table1>
<Table1 diffgr:id="Table16" msdata:rowOrder="5">
<AI>05</AI>
<Descr>DAILYTANK </Descr>
<Min_I>0.004</Min_I>
<Max_I>0.02</Max_I>
<Min_Val>0</Min_Val>
<Max_Val>300</Max_Val>
<R>120</R>
<Value>180.02</Value>
<LowRange>0</LowRange>
<HighRange>1000</HighRange>
<Enable>true</Enable>
<unt>M3 </unt>
<monitor_var>DAILYTANK </monitor_var>
<HaveSum>false</HaveSum>
<SumCoef>0.0006786111111109171</SumCoef>
<SumValue>0</SumValue>
<SumReset>1</SumReset>
<UpDownward>U</UpDownward>
<Sumation>540.06000000000006</Sumation>
<Total>3</Total>
<SaveTime>54608.013</SaveTime>
<rate>2.4429999999993015</rate>
</Table1>
<Table1 diffgr:id="Table17" msdata:rowOrder="6">
<AI>06</AI>
<Descr>RO500 </Descr>
<Min_I>0.004</Min_I>
<Max_I>0.02</Max_I>
<Min_Val>0</Min_Val>
<Max_Val>50</Max_Val>
<R>120</R>
<Value>-12.468</Value>
<LowRange>0</LowRange>
<HighRange>50</HighRange>
<Enable>true</Enable>
<unt>M3H </unt>
<monitor_var>RO1000 </monitor_var>
<HaveSum>false</HaveSum>
<SumCoef>0.00067777777777842452</SumCoef>
<SumValue>0</SumValue>
<SumReset>1</SumReset>
<UpDownward>U</UpDownward>
<Sumation>0</Sumation>
<Total>3</Total>
<SaveTime>54608.05</SaveTime>
<rate>2.4400000000023283</rate>
</Table1>
<Table1 diffgr:id="Table18" msdata:rowOrder="7">
<AI>07</AI>
<Descr> </Descr>
<Min_I>0.004</Min_I>
<Max_I>0.02</Max_I>
<Min_Val>0</Min_Val>
<Max_Val>400</Max_Val>
<R>120.014</R>
<Value>15.639</Value>
<LowRange>0</LowRange>
<HighRange>400</HighRange>
<Enable>true</Enable>
<unt>M3H </unt>
<monitor_var>BANDARGAH </monitor_var>
<HaveSum>true</HaveSum>
<SumCoef>0.0006786111111109171</SumCoef>
<SumValue>1133118.176131512</SumValue>
<SumReset>999999999999</SumReset>
<UpDownward>U</UpDownward>
<Sumation>47.108000000000004</Sumation>
<Total>3</Total>
<SaveTime>54608.09</SaveTime>
<rate>2.4429999999993015</rate>
</Table1>
<Table1 diffgr:id="Table19" msdata:rowOrder="8">
<AI>08</AI>
<Descr> 1 </Descr>
<Min_I>0.004</Min_I>
<Max_I>0.02</Max_I>
<Min_Val>0</Min_Val>
<Max_Val>11.74</Max_Val>
<R>120</R>
<Value>7.203</Value>
<LowRange>0</LowRange>
<HighRange>12.5</HighRange>
<Enable>true</Enable>
<unt>Litr </unt>
<monitor_var>FuelStorage1 </monitor_var>
<HaveSum>false</HaveSum>
<SumCoef>0.0006797222222222546</SumCoef>
<SumValue>0</SumValue>
<SumReset>1</SumReset>
<UpDownward>U</UpDownward>
pritaeas 2,194 ¯\_(ツ)_/¯ Moderator Featured Poster
IIRC a DataSet
has a LoadFromFile
method which you can use to read the returned XML.
fayyaz 1 Junior Poster in Training
I Dont want to read XML File To a Dataset. I want to get the result of webservice methode as a Table;
On the outher hand
TClientDataset hase LoadFromFile method but it raise a run time error when I Try to load XML File
pritaeas 2,194 ¯\_(ツ)_/¯ Moderator Featured Poster
I want to get the result of webservice methode as a Table;
Not sure how to put XML in a Table component.
but it raise a run time error
What's the error?
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.