Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/276.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#读取带有动态生成标记的XML文件_C#_Xml_Xml Parsing - Fatal编程技术网

C#读取带有动态生成标记的XML文件

C#读取带有动态生成标记的XML文件,c#,xml,xml-parsing,C#,Xml,Xml Parsing,我正在使用C#(.NETFramework4withVS2010)来读取动态生成的XML文件。该文件包含问题的答案(MCQ单选按钮、MCQ多答案复选框和简单文本字段)。问题ID和选项ID是从数据库生成的 我只需要提取问题ID和相关答案ID。示例XML如下所示 <?xml version="1.0"?> <Root> <!-- Radio Button Answers --> <Question_6_Option>26</Q

我正在使用C#(.NETFramework4withVS2010)来读取动态生成的XML文件。该文件包含问题的答案(MCQ单选按钮、MCQ多答案复选框和简单文本字段)。问题ID和选项ID是从数据库生成的

我只需要提取问题ID和相关答案ID。示例XML如下所示

<?xml version="1.0"?>
<Root>
   <!-- Radio Button Answers -->    
   <Question_6_Option>26</Question_6_Option>
   <Question_8_Option>32</Question_8_Option>
   <Question_9_Option>off</Question_9_Option>
   <!-- Check Box Answers -->
   <Question_15_Option_41>41</Question_15_Option_41>
   <Question_15_Option_42>off</Question_15_Option_42>
   <Question_16_Option_43>43</Question_16_Option_43>
   <!-- Text Box Answers -->
   <Question_23_Text>London</Question_23_Text>
</Root>

26
32
关
41
关
43
伦敦
上述XML以以下格式生成:

标记名格式:问题\问题ID \基于答案类型的逻辑(收音机、多选项或文本框)

如果用户未回答问题,则值将显示为“关闭”。这些都不需要考虑。 如何从C#获取问题ID和答案值

谢谢


Chatur不是答案,而是包含在此处而不是注释中,以使XML更具可读性:

我建议,如果您能够使XML更易于计算机读取,也就是说,从标记名中删除数据并将其放入属性中,以简化解析

<?xml version="1.0"?>
<Root>
    <!-- Radio Button Answers -->    
    <Question number="6" type="radio"><Selected index="26" /></Question>
    <Question number="8" type="radio"><Selected index="32" /></Question>
    <Question number="9" type="radio" />
    <!-- Check Box Answers -->
    <Question number="15" type="check">
        <Selected index="41" />
        <Selected index="42" /><!-- not sure if this should be included, I didn't understand how question 15 was both off (unanswered) and 41 (answered) -->
    </Question>
    <Question number="16" type="check">
        <Selected index="43" />
    </Question>
    <!-- Text Box Answers -->
    <Question number="23" type="text">London</Question>
</Root>

伦敦

正如@newagrition所述,您的实际问题的答案已经在本网站的其他地方了。

好的先生,我相信这是对以下问题的重复。请记住在发布问题之前搜索它。不是anwser,而是谁生成了xml?我觉得真的很糟糕。如果你是程序员,你应该考虑改变结构,你可以使用ReXEP元素的名称,但是一般来说,这是错误的XML格式,如果可能的话,首先改变一下:你到目前为止尝试了什么?实例化一个XDocument,然后枚举它的所有XElement,在它们的名称上运行regexp就可以了。。。在复选框中,回答元素中的最后一个数字是什么?