【发布时间】:2011-10-29 20:21:26
【问题描述】:
我正在尝试创建一个 API XML,其中包含来自 MySQL 数据库的数据。我正在尝试实现以下目标。
<api xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<key>eee83d24-906b-4736-91d9-1031621b79eb</key>
<name>API Test</name>
<feedState>Test</feedState>
<news href="http://api.mydomain.com/eee83d24-906b-4736-91d9-1031621b79eb/news/"/>
<comments href="http://api.mydomain.com/eee83d24-906b-4736-91d9-1031621b79eb/comments/"/>
</api>
如果我打开浏览器并输入下面的 URL,我可以看到上面的 XML
http://api.mydomain.com/eee83d24-906b-4736-91d9-1031621b79eb
现在,如果我需要在“新闻”中查看详细信息,我现在只需将浏览器指向,
http://api.mydomain.com/eee83d24-906b-4736-91d9-1031621b79eb/news
这样做之后,我会看到类似的东西,
<news xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" state="Trial">
<newsListItem href="http://api.mydomain.com/eee83d24-906b-4736-91d9-1031621b79eb/news/800577419/">
<id>800577419</id>
<publishDate>2011-08-17</publishDate>
<lastModifiedDate>2011-08-17</lastModifiedDate>
<headline>Google buys Motorola</headline>
</newsListItem>
<newsListItem href="http://api.mydomain.com/eee83d24-906b-4736-91d9-1031621b79eb/news/800577416/">
<id>800577416</id>
<publishDate>2011-08-17T15:13:12</publishDate>
<lastModifiedDate>2011-08-17T15:14:36</lastModifiedDate>
<headline>Apple Macbook Air</headline>
</newsListItem>
</news>
记住上面显示的所有数据都来自 MySQL 数据库。
我怎样才能实现上述目标?欢迎任何示例示例,想法。如果有人可以扔灯,我将不胜感激。 WCF是要走的路吗?还是使用普通的旧 ASP.NET XDoc 等...?
请指教。非常感谢!
【问题讨论】:
标签: xml xml-serialization linq-to-xml wcf-rest