xml到数据结构
我有一个如下所示的 xml 文件
<step>
<id>3</id>
<backid>1</backid>
<question>Are you having a good day</question>
<yesid>4</yesid>
<noid>5</noid>
</step>
它被设置为一个应用程序,询问用户是或否问题,以帮助指导用户完成复杂的业务流程。 yesid 和 noid 是该过程下一步的 id 号。在过去(以及在其他语言中),我会将 xml 文件中的信息加载到多维数组中,然后从那里开始。
不过,我正在尝试在此应用程序中使用 linq to xml,并且我想知道是否有比我过去所做的 xpath to array 更有效的方法
I have an xml file that looks like this
<step>
<id>3</id>
<backid>1</backid>
<question>Are you having a good day</question>
<yesid>4</yesid>
<noid>5</noid>
</step>
It's set up to be an application that asks the user yes and no questions to assist in guiding the user through a complicated business process. The yesid and noid are the id numbers of the next step of the process. In the past (and in other languages) I would have loaded the info from the xml file into a multidimensional array and gone from there.
However I am attempting to use linq to xml in this application and I am wondering if there is a more efficient way of doing this than the xpath to array that I have been doing in the past
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我将创建一个表示步骤的类,使用 LINQ-to-XML 将 XML 文件读入其中,然后创建一个步骤字典以便于查找:(
假设该文件在公共根下包含多个元素。 )
I would create a class that represents a step, read the XML file into it using LINQ-to-XML, and then create a dictionary of steps for easy lookup:
(Assuming the file contains several <step> elements under a common root.)