我需要以XML格式返回数据集,以便Flash可以正确读取它。 [英] I need to return dataset in XML format so Flash can read it properly.

查看:56
本文介绍了我需要以XML格式返回数据集,以便Flash可以正确读取它。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的webservice中作为XMLDataDocument返回,但它返回的不是

,其中包含名称空间等。任何人都有和我可以的例子
让webservice将它作为XML返回。 C#首选。

Flash只是在调用Web服务时将其视为对象。

谢谢

I do a return as XMLDataDocument in my webservice but it returns not
with the namespaces etc in them. Anyone have and example where I can
have the webservice return it as a XML. C# preferred.
Flash just sees it as an object when it calls the web service.
Thanks

推荐答案

< ca ***** @ gmail.comwrote in message

news:27 ******************** ************** @ 8g2000hs e.googlegroups.com ...
<ca*****@gmail.comwrote in message
news:27**********************************@8g2000hs e.googlegroups.com...

我在我的网络服务中作为XMLDataDocument返回但是它返回的不是

,其中包含名称空间等。任何人都有和我可以的例子
让webservice将它作为XML返回。 C#首选。

Flash在调用Web服务时只是将其视为对象。
I do a return as XMLDataDocument in my webservice but it returns not
with the namespaces etc in them. Anyone have and example where I can
have the webservice return it as a XML. C# preferred.
Flash just sees it as an object when it calls the web service.



你是什么意思,没有命名空间?你能详细介绍一下你要找的

吗?

-

John Saunders | MVP - 连接系统开发人员

What do you mean, "without the namespaces"? Can you give more detail on what
you''re looking for?
--
John Saunders | MVP - Connected System Developer


10月2日,12:20 * pm,John Saunders < n ... @ dont.do.that.comwrote:
On Oct 2, 12:20*pm, "John Saunders" <n...@dont.do.that.comwrote:

< casu ... @ gmail.comwrote in message


news:27 ********************************** @ 8g2000hs e.googlegroups.com。 ..
<casu...@gmail.comwrote in message

news:27**********************************@8g2000hs e.googlegroups.com...

我在我的webservice中作为XMLDataDocument返回,但它返回的不是

,其中包含名称空间等。任何人都有和我可以的例子
让webservice将它作为XML返回。 C#首选。

Flash在调用Web服务时只是将其视为对象。
I do a return as XMLDataDocument in my webservice but it returns not
with the namespaces etc in them. Anyone have and example where I can
have the webservice return it as a XML. C# preferred.
Flash just sees it as an object when it calls the web service.



你是什么意思,没有命名空间?你能详细介绍一下你要找的是什么吗?


-

John Saunders | MVP - Connected System Developer


What do you mean, "without the namespaces"? Can you give more detail on what
you''re looking for?

--
John Saunders | MVP - Connected System Developer



这是我的代码:

[WebMethod(Description =" Get All Floors",EnableSession = true) ]

public XmlDocument GetCurrentFloor(字符串标识)

{

DataTable dt;

尝试

{

我在数据库中获取数据集

XmlDocument xml = new XmlDocument();

xml.LoadXml(dt。 DataSet.GetXml());

返回xml;

}

catch(SoapException sox)

{

扔袜子;

}


它返回如下:

<?xml version = " 1.0"编码= QUOT; UTF-8英寸?>

- < NewDataSet>

- <表1>

< FirstName> Ari N.< / FirstName>

< LastName> Lefkovits< / LastName>

< Title> Director< / title>

< Email> ar **** ******* @ lazard.com< / Email>

< Phone> +1 212-555-5555< / Phone>

< BusinessLine> Clothinh< / BusinessLine>

< DepartmentName> industry< / DepartmentName>

< DepartmentId> 188989< / DepartmentId>

< ProductGroup> ; 55555< / ProductGroup>

< Assistant xml:space =" preserve">< / Assistant>

< FloorLocationId> 177< / FloorLocationId>

< UserName> name< / UserName>

< LazardId> 6666< / LazardId>

< Location> New York< / Location> ;

< Floor> 61< / Floor>

< BusinessUnit> 3333< / BusinessUnit>

< CPUGroup> 1< ; / CPUGroup>

< / Table1> ...........


我需要它像这样返回:

<?xml version =" 1.0"编码= QUOT; UTF-8英寸?>

- < WeatherForecasts xmlns:xsd =" http://www.w3.org/2001/XMLSchema"

xmlns:xsi =" http ://www.w3.org/2001/XMLSchema-instance" xmlns =" http://

www.webservicex.net">

< Latitude> 40.7597275< / Latitude>

<经度> 73.9823456< /经度>

< AllocationFactor> 2.2E-05< / AllocationFactor>

< FipsCode> 36< / FipsCode>

< PlaceName>纽约< / PlaceName>

< StateCode> NY< / StateCode>

- <详情>

- < WeatherData>

< Day> 2008年10月2日星期四< / day>

< WeatherImage> http://forecast.weather。 gov / images / wtf / shra20.jpg< /

WeatherImage>

< MaxTemperatureF> 68< / MaxTemperatureF>

< MinTemperatureF> 51< / MinTemperatureF>

< MaxTemperatureC> 20< / MaxTemperatureC>

< MinTemperatureC> 11< / MinTemperatureC>

< / WeatherData>

- < WeatherData>

< Day> 2008年10月3日星期五< / day>

< WeatherImage> http://forecast.weather.gov/images/wtf/sct.jpg< /

WeatherImage>

< MaxTemperatureF> ; 69< / MaxTemperatureF>

< MinTemperatureF> 53< / MinTemperatureF>

< MaxTemperatureC> 21< / MaxTemperatureC>

< MinTemperatureC> 12< / MinTemperatureC>

< / WeatherData>

- < WeatherData>

< Day>星期六,10月04日, 2008< / Day>

< WeatherImage> http://forecast.weather.gov/images/wtf/sct.jpg< /

WeatherImage>

< MaxTemperatureF> 66< / MaxTemperatureF>

< MinTemperatureF> 51< / MinTemperatureF>

< MaxTemperatureC> 19< / MaxTemperatureC>

< MinTemperatureC> 11< / MinTemperatureC>

< / WeatherData>

- < WeatherData>

< Day> 2008年10月5日星期日< / Day>

< WeatherImage> http:// forec ast.weather.gov/images/wtf/sct.jpg</

WeatherImage>

< MaxTemperatureF> 64< / MaxTemperatureF>

< MinTemperatureF> 48< / MinTemperatureF>

< MaxTemperatureC> 18< / MaxTemperatureC>

< MinTemperatureC> 9< / MinTemperatureC>

< / WeatherData>

- < WeatherData>

< Day> 2008年10月6日星期一< / Day>

< ; WeatherImage> http://forecast.weather.gov/images/wtf/sct.jpg< /

WeatherImage>

< MaxTemperatureF> 62< / MaxTemperatureF>

< MinTemperatureF> 48< / MinTemperatureF>

< MaxTemperatureC> 17< / MaxTemperatureC>

< MinTemperatureC> 9< / MinTemperatureC>

< / WeatherData>

- < WeatherData>

< Day> 2008年10月7日星期二< / day>

< WeatherImage> http://forecast.weather.gov/images/wtf/sct.jpg< /

WeatherImage>

< MaxTemperatureF> 61< / MaxTemperatureF>

< MinTemperatureF> 52< / MinTemperatureF>

< MaxTemperatureC> 16< / MaxTemperatureC>

< MinTemperatureC> 11< / MinTemperatureC>

< / WeatherData>

< WeatherData />

< / Details>

< / WeatherForecasts>

Here is my code:
[WebMethod(Description = "Get All Floors", EnableSession = true)]
public XmlDocument GetCurrentFloor(string identity)
{
DataTable dt;
try
{
I get my dataset here from the database
XmlDocument xml = new XmlDocument();
xml.LoadXml(dt.DataSet.GetXml());
return xml;
}
catch (SoapException sox)
{
throw sox;
}

it returns as this:
<?xml version="1.0" encoding="utf-8" ?>
- <NewDataSet>
- <Table1>
<FirstName>Ari N.</FirstName>
<LastName>Lefkovits</LastName>
<Title>Director</Title>
<Email>ar***********@lazard.com</Email>
<Phone>+1 212-555-5555</Phone>
<BusinessLine>Clothinh</BusinessLine>
<DepartmentName>industry</DepartmentName>
<DepartmentId>188989</DepartmentId>
<ProductGroup>55555</ProductGroup>
<Assistant xml:space="preserve"></Assistant>
<FloorLocationId>177</FloorLocationId>
<UserName>name</UserName>
<LazardId>6666</LazardId>
<Location>New York</Location>
<Floor>61</Floor>
<BusinessUnit>3333</BusinessUnit>
<CPUGroup>1</CPUGroup>
</Table1>...........

I need it to return it like this:
<?xml version="1.0" encoding="utf-8" ?>
- <WeatherForecasts xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://
www.webservicex.net">
<Latitude>40.7597275</Latitude>
<Longitude>73.9823456</Longitude>
<AllocationFactor>2.2E-05</AllocationFactor>
<FipsCode>36</FipsCode>
<PlaceName>NEW YORK</PlaceName>
<StateCode>NY</StateCode>
- <Details>
- <WeatherData>
<Day>Thursday, October 02, 2008</Day>
<WeatherImage>http://forecast.weather.gov/images/wtf/shra20.jpg</
WeatherImage>
<MaxTemperatureF>68</MaxTemperatureF>
<MinTemperatureF>51</MinTemperatureF>
<MaxTemperatureC>20</MaxTemperatureC>
<MinTemperatureC>11</MinTemperatureC>
</WeatherData>
- <WeatherData>
<Day>Friday, October 03, 2008</Day>
<WeatherImage>http://forecast.weather.gov/images/wtf/sct.jpg</
WeatherImage>
<MaxTemperatureF>69</MaxTemperatureF>
<MinTemperatureF>53</MinTemperatureF>
<MaxTemperatureC>21</MaxTemperatureC>
<MinTemperatureC>12</MinTemperatureC>
</WeatherData>
- <WeatherData>
<Day>Saturday, October 04, 2008</Day>
<WeatherImage>http://forecast.weather.gov/images/wtf/sct.jpg</
WeatherImage>
<MaxTemperatureF>66</MaxTemperatureF>
<MinTemperatureF>51</MinTemperatureF>
<MaxTemperatureC>19</MaxTemperatureC>
<MinTemperatureC>11</MinTemperatureC>
</WeatherData>
- <WeatherData>
<Day>Sunday, October 05, 2008</Day>
<WeatherImage>http://forecast.weather.gov/images/wtf/sct.jpg</
WeatherImage>
<MaxTemperatureF>64</MaxTemperatureF>
<MinTemperatureF>48</MinTemperatureF>
<MaxTemperatureC>18</MaxTemperatureC>
<MinTemperatureC>9</MinTemperatureC>
</WeatherData>
- <WeatherData>
<Day>Monday, October 06, 2008</Day>
<WeatherImage>http://forecast.weather.gov/images/wtf/sct.jpg</
WeatherImage>
<MaxTemperatureF>62</MaxTemperatureF>
<MinTemperatureF>48</MinTemperatureF>
<MaxTemperatureC>17</MaxTemperatureC>
<MinTemperatureC>9</MinTemperatureC>
</WeatherData>
- <WeatherData>
<Day>Tuesday, October 07, 2008</Day>
<WeatherImage>http://forecast.weather.gov/images/wtf/sct.jpg</
WeatherImage>
<MaxTemperatureF>61</MaxTemperatureF>
<MinTemperatureF>52</MinTemperatureF>
<MaxTemperatureC>16</MaxTemperatureC>
<MinTemperatureC>11</MinTemperatureC>
</WeatherData>
<WeatherData />
</Details>
</WeatherForecasts>


< ca *** **@gmail.com在留言中写道

新闻:da ******************************* *** @ m45g2000 hsb.googlegroups.com ...
<ca*****@gmail.comwrote in message
news:da**********************************@m45g2000 hsb.googlegroups.com...

10月2日下午12:20,John Saunders < n ... @ dont.do.that.comwrote:
On Oct 2, 12:20 pm, "John Saunders" <n...@dont.do.that.comwrote:

>< casu ... @ gmail.comwrote in message
<新闻:27 ********************************** @ 8g2000h se.googlegroups.com ...
><casu...@gmail.comwrote in message

news:27**********************************@8g2000h se.googlegroups.com...

我在我的webservice中作为XMLDataDocument返回,但它返回的不是

,其中包含名称空间等。任何人都有和我可以的例子
让webservice将它作为XML返回。 C#首选。

Flash在调用Web服务时只是将其视为对象。
I do a return as XMLDataDocument in my webservice but it returns not
with the namespaces etc in them. Anyone have and example where I can
have the webservice return it as a XML. C# preferred.
Flash just sees it as an object when it calls the web service.


你是什么意思,没有命名空间?你能详细介绍一下
你在寻找什么?

-
John Saunders | MVP - 连接系统开发人员


What do you mean, "without the namespaces"? Can you give more detail on
what
you''re looking for?

--
John Saunders | MVP - Connected System Developer



这是我的代码:

[WebMethod(Description =" Get All Floors",EnableSession = true) ]

public XmlDocument GetCurrentFloor(字符串标识)

{

DataTable dt;

尝试

{

我在数据库中获取数据集

XmlDocument xml = new XmlDocument();

xml.LoadXml(dt。 DataSet.GetXml());

返回xml;

}

catch(SoapException sox)

{

扔袜子;

}


它返回如下:

<?xml version = " 1.0"编码= QUOT; UTF-8英寸?>

- < NewDataSet>

- <表1>

< FirstName> Ari N.< / FirstName>

< LastName> Lefkovits< / LastName>

< Title> Director< / title>

< Email> ar **** ******* @ lazard.com< / Email>

< Phone> +1 212-555-5555< / Phone>

< BusinessLine> Clothinh< / BusinessLine>

< DepartmentName> industry< / DepartmentName>

< DepartmentId> 188989< / DepartmentId>

< ProductGroup> ; 55555< / ProductGroup>

< Assistant xml:space =" preserve">< / Assistant>

< FloorLocationId> 177< / FloorLocationId>

< UserName> name< / UserName>

< LazardId> 6666< / LazardId>

< Location> New York< / Location> ;

< Floor> 61< / Floor>

< BusinessUnit> 3333< / BusinessUnit>

< ; CPUGroup> 1< / CPUGroup>

< / Table1> ...........


我需要它来返回它像这样:

<?xml version =" 1.0"编码= QUOT; UTF-8英寸?>

- < WeatherForecasts xmlns:xsd =" http://www.w3.org/2001/XMLSchema"

xmlns:xsi =" http ://www.w3.org/2001/XMLSchema-instance" xmlns =" http://

www.webservicex.net">

< Latitude> 40.7597275< / Latitude>

<经度> 73.9823456< /经度>

< AllocationFactor> 2.2E-05< / AllocationFactor>

< FipsCode> 36< / FipsCode>

< PlaceName>纽约< / PlaceName>

< StateCode> NY< / StateCode>

- <详情>

- < WeatherData>

< Day> 2008年10月2日星期四< / day>

< WeatherImage> http://forecast.weather。 gov / images / wtf / shra20.jpg< /

WeatherImage>

< MaxTemperatureF> 68< / MaxTemperatureF>

< MinTemperatureF> 51< / MinTemperatureF>

< MaxTemperatureC> 20< / MaxTemperatureC>

< MinTemperatureC> 11< / MinTemperatureC>

< / WeatherData>

- < WeatherData>

< Day> 2008年10月3日星期五&l t; / Day>

< WeatherImage> http://forecast.weather.gov/images/wtf/sct.jpg< /

WeatherImage>

< MaxTemperatureF> 69< / MaxTemperatureF>

< MinTemperatureF> 53< / MinTemperatureF>

< MaxTemperatureC> 21< / MaxTemperatureC>

< MinTemperatureC> 12< / MinTemperatureC>

< / WeatherData>

- < WeatherData>

<日> 2008年10月4日星期六< /日>

< WeatherImage> http://forecast.weather.gov/images/wtf/sct.jpg< /

WeatherImage>

< MaxTemperatureF> 66< / MaxTemperatureF>

< MinTemperatureF> 51< / MinTemperatureF>

< MaxTemperatureC> 19< ; / MaxTemperatureC>

< MinTemperatureC> 11< / MinTemperatureC>

< / WeatherData>

- < WeatherData>

< Day> 2008年10月5日星期日< / day>

< ; WeatherImage> http://forecast.weather.gov/images/wtf/sct.jpg< /

WeatherImage>

< MaxTemperatureF> 64< / MaxTemperatureF>

< MinTemperatureF> 48< / MinTemperatureF>

< MaxTemperatureC> 18< / MaxTemperatureC>

< MinTemperatureC> 9< / MinTemperatureC>

< / WeatherData>


Here is my code:
[WebMethod(Description = "Get All Floors", EnableSession = true)]
public XmlDocument GetCurrentFloor(string identity)
{
DataTable dt;
try
{
I get my dataset here from the database
XmlDocument xml = new XmlDocument();
xml.LoadXml(dt.DataSet.GetXml());
return xml;
}
catch (SoapException sox)
{
throw sox;
}

it returns as this:
<?xml version="1.0" encoding="utf-8" ?>
- <NewDataSet>
- <Table1>
<FirstName>Ari N.</FirstName>
<LastName>Lefkovits</LastName>
<Title>Director</Title>
<Email>ar***********@lazard.com</Email>
<Phone>+1 212-555-5555</Phone>
<BusinessLine>Clothinh</BusinessLine>
<DepartmentName>industry</DepartmentName>
<DepartmentId>188989</DepartmentId>
<ProductGroup>55555</ProductGroup>
<Assistant xml:space="preserve"></Assistant>
<FloorLocationId>177</FloorLocationId>
<UserName>name</UserName>
<LazardId>6666</LazardId>
<Location>New York</Location>
<Floor>61</Floor>
<BusinessUnit>3333</BusinessUnit>
<CPUGroup>1</CPUGroup>
</Table1>...........

I need it to return it like this:
<?xml version="1.0" encoding="utf-8" ?>
- <WeatherForecasts xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://
www.webservicex.net">
<Latitude>40.7597275</Latitude>
<Longitude>73.9823456</Longitude>
<AllocationFactor>2.2E-05</AllocationFactor>
<FipsCode>36</FipsCode>
<PlaceName>NEW YORK</PlaceName>
<StateCode>NY</StateCode>
- <Details>
- <WeatherData>
<Day>Thursday, October 02, 2008</Day>
<WeatherImage>http://forecast.weather.gov/images/wtf/shra20.jpg</
WeatherImage>
<MaxTemperatureF>68</MaxTemperatureF>
<MinTemperatureF>51</MinTemperatureF>
<MaxTemperatureC>20</MaxTemperatureC>
<MinTemperatureC>11</MinTemperatureC>
</WeatherData>
- <WeatherData>
<Day>Friday, October 03, 2008</Day>
<WeatherImage>http://forecast.weather.gov/images/wtf/sct.jpg</
WeatherImage>
<MaxTemperatureF>69</MaxTemperatureF>
<MinTemperatureF>53</MinTemperatureF>
<MaxTemperatureC>21</MaxTemperatureC>
<MinTemperatureC>12</MinTemperatureC>
</WeatherData>
- <WeatherData>
<Day>Saturday, October 04, 2008</Day>
<WeatherImage>http://forecast.weather.gov/images/wtf/sct.jpg</
WeatherImage>
<MaxTemperatureF>66</MaxTemperatureF>
<MinTemperatureF>51</MinTemperatureF>
<MaxTemperatureC>19</MaxTemperatureC>
<MinTemperatureC>11</MinTemperatureC>
</WeatherData>
- <WeatherData>
<Day>Sunday, October 05, 2008</Day>
<WeatherImage>http://forecast.weather.gov/images/wtf/sct.jpg</
WeatherImage>
<MaxTemperatureF>64</MaxTemperatureF>
<MinTemperatureF>48</MinTemperatureF>
<MaxTemperatureC>18</MaxTemperatureC>
<MinTemperatureC>9</MinTemperatureC>
</WeatherData>



....

....


< / Details>

< ; / WeatherForecasts>
</Details>
</WeatherForecasts>



首先,你发布了正确的XML吗?第一个例子似乎与第二个例子没有关系。


其次,当你谈到命名空间时,我认为你的意思是

xmlns =" http://www.webservicex.net"?如果这是真的,那么尝试将DataSet的

Namespace属性设置为http://www.webservicex.net" ;.


第三,除非你必须这样做,否则永远不会捕获异常,除非你想要增加一些东西,如果你没有捕获,将会发生的事情

例外。所有你正在做的就是抛出你抓到的东西,这比没有抓住它更糟糕(你正在弄乱堆栈痕迹)。


最后,还有其他几种将gettinig XML从DataSet转换为
的XmlDocument方法。我还没有时间对他们进行性能测试,看看

哪个更好,但我肯定你选择了最糟糕的方式

可能。在要求DataSet以字符串形式发出其内容之后,您将转向
然后转身并要求XmlDocument实例解析

字符串。这可能是一项非常昂贵的操作。试试其中一个:


public XmlDocument GetDocument()

{

返回新的XmlDataDocument(_ds);

}


public XmlDocument GetDocument()

{

XmlDocument doc = new XmlDocument();

XPathNavigator navigator = doc.CreateNavigator();

using(var writer = navigator.AppendChild())

{

_ds.WriteXml(writer,XmlWriteMode.IgnoreSchema);

}

返回doc;

}


-

John Saunders | MVP - 连接系统开发人员

First of all, did you post the correct XML? The first example seems
unrelated to the second example.

Second of all, when you talk about namespace, I presume you mean
xmlns="http://www.webservicex.net"? If that''s true, then try setting the
Namespace property of the DataSet to "http://www.webservicex.net".

Third, never ever catch exceptions unless you have to, and unless you''re
going to add something over and above what would happen if you didn''t catch
the exception. All you are doing is throwing what you caught, which is worse
than not catching it (you''re screwing up the stack trace).

Finally, there are several other methods of gettinig XML from a DataSet into
an XmlDocument. I haven''t had time to do performance testing on them to see
which is better, but I''m certain that you''ve chosen about the worst way
possible. After asking the DataSet to emit its contents as a string, you''re
then turning around and asking the XmlDocument instance to parse that
string. That can be a very expensive operation. Try one of these:

public XmlDocument GetDocument()
{
return new XmlDataDocument(_ds);
}

public XmlDocument GetDocument()
{
XmlDocument doc = new XmlDocument();
XPathNavigator navigator = doc.CreateNavigator();
using (var writer = navigator.AppendChild())
{
_ds.WriteXml(writer, XmlWriteMode.IgnoreSchema);
}
return doc;
}

--
John Saunders | MVP - Connected System Developer


这篇关于我需要以XML格式返回数据集,以便Flash可以正确读取它。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆