如何从两个xml文件中获取相关数据. [英] How to fetch related data from two xml files .

查看:90
本文介绍了如何从两个xml文件中获取相关数据.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好

我有两个xml文件
一个是 WROOMCATEGORY

Hello

I have two xml files
one is WROOMCATEGORY

<?xml version="1.0" standalone="yes" ?>
<DocumentElement>
  <tblCategory>
    <CatID>1</CatID>
    <CatCode>DX</CatCode>
    <Category>DELUXE</Category>
  </tblCategory>
</DocumentElement>


其他是
WROOMMASTER


and other is
WROOMMASTER

<?xml version="1.0" standalone="yes" ?>
<DocumentElement>
  <tblRooms>
    <RoomID>1</RoomID>
    <RoomNo>102</RoomNo>
    <CategoryID>1</CategoryID>
    <RoomStatus>Available</RoomStatus>
    <Floor>First</Floor>
    <Tax>10</Tax>
  </tblRooms>
  <tblRooms>
    <RoomID>2</RoomID>
    <RoomNo>121</RoomNo>
    <CategoryID>1</CategoryID>
    <RoomStatus>Available</RoomStatus>
    <Floor>first</Floor>
    <Tax>10</Tax>
  </tblRooms>
  <tblRooms>
    <RoomID>3</RoomID>
    <RoomNo>122</RoomNo>
    <CategoryID>1</CategoryID>
    <RoomStatus>Available</RoomStatus>
    <Floor>Second</Floor>
    <Tax>10</Tax>
  </tblRooms>
</DocumentElement>


我想两个以网格视图显示所有房间.
我将gridview绑定到 WROOMMASTER xml文件,但是它包含 CategoryID

我想显示类别而不是来自WROOMCATEGORY文件的categoryID;
为此,我正在GridView的RowDataBound上的WROOMCATEGORY中检查CatID,并显示相应的Category.


I want two show all rooms in a grid view.
I am binding gridview to WROOMMASTERxml file but it contains CategoryID

I want to show Category instead of categoryID which comes from WROOMCATEGORY file;
For this I am checking CatID from WROOMCATEGORY on RowDataBound of gridview and showing corresponding Category.

Is this the right way or is there another proper way to do this?

推荐答案

有三种方法可以解决此问题:

使用数据协定,您只需序列化xml并将您的显示绑定到该类,这使您可以在编译时随意更改名称,只需从第一个文件(WROOMCATEGORY)设置一个管理器类即可. >
使用XSLT,您可以对xml进行预处理,然后再将其读入现有代码中(这种声音对于这种简单的转换来说是最简单的),这是很常见的做法,因此您可以通过google-ing找到所需的内容(这种方法可以如果要在xml文件之间具有多个依赖关系,也可以使用它,有些人可能会发现这种令人恐惧的内容.

最后,您可以执行听起来好像已经使用了幕后"魔术一样的操作,并且只需在提取值后更改显示文本,就必须使用一个隐藏"变量进行控制(catagoryId?),然后返回并进行相应的修改...

如果将来会出现很多情况,那么我建议您使用XSLT方法,如果您希望这种方法能可靠地工作并且可以访问硬盘驱动器,或者xml位于静态文件中,则建议使用XSLT方法.您正在执行此操作,我建议您使用数据合约方法,如果您只是想让它起作用,那么这将是唯一使用幕后方法的方法...

祝你好运. ; P
There are three ways to solve this problem:

Using data contracts, you just serialize the xml and bind your display to the class, this allows you to make the name whatever you want at compile time really easy, just set up a manager class from your first file (WROOMCATEGORY).

Using XSLT you can pre-process the xml before you read it into your existing code (sounds like this would be the easiest for this simple conversion) this is very commonly done so you can find what you need by google-ing (this approach can also be used if you want to have multiple dependancies between xml files, some might find this intimidating.

Lastly you can do the same thing it sounds like your already doing with a bit of "behind the scenes" magic and just change the display text after you pull the values, you''ll have to have a "hidden" variable that you use for control (catagoryId?) and then go back and modify accordingly...

if it is going to be a matter of having many of these situations in the future for out code I recommend the XSLT approach, if you want this to work robustly, and have access to the hard drive or the xml is in a static file where you are doing this, i recommend the data contract approach, if you just want it to work and this will be the only one use the behind the scenes approach...

Good Luck. ;P


这篇关于如何从两个xml文件中获取相关数据.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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