我有以下xml代码,我想读入数据集:
<?xml version="1.0" standalone="yes"?>
<jlqn:Root xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:jlqn="http://jlqn/1.0">
<element xsi:type="jlqn:Processor" name="test1" processor="test">
<metadata name="Removed" value="False" />
<task id="6">
<entry id="8" entry="" />
</task>
</element>
<element xsi:type="jlqn:Processor" name="test1" processor="test" id="1">
<metadata name="Removed" value="True" />
<metadata name="Removed1" value="Removed1" />
</element>
<element xsi:type="jlqn:Processor" name="test1" processor="test" id="3">
<metadata name="Removed" value="False" />
<task id="45" name="">
<metadata />
<entry id="10" entry="">
<metadata />
</entry>
</task>
</element>
<element name="test" />
</jlqn:Root>
我使用以下C#代码
DataSet newTable = new DataSet();
newTable.ReadXml(@"F:\QVT\runtime-EclipseApplication\dr5\HJYU.jlqn");
但是当我检查数据集时,我注意到所有带前缀的属性都没有被读取..就像这样:xsi:type =“jlqn:Processor”
我该怎么办?
答案 0 :(得分:0)
XML引用名称空间前缀&#34; xsi&#34;,但未定义。将根元素更改为:
<jlqn:Root xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:jlqn="http://jlqn/1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
一旦我这样做,我得到了以下表格和列:
Root
Root_Id
version
element
element_Id
name
processor
id
Root_Id
metadata
name
value
element_Id
task
metadata
task_Id
id
name
element_Id
entry
metadata
id
entry
task_Id
这是来自:
的输出DataSet newTable = new DataSet();
newTable.ReadXml(@"XMLFile1.xml");
foreach(DataTable table in newTable.Tables)
{
Console.WriteLine(table.TableName);
foreach(DataColumn column in table.Columns)
{
Console.WriteLine(" " + column.ColumnName);
}
}