1

我有一个如下所示的 XML 文档:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="CoreNLP-to-HTML.xsl" type="text/xsl"?>
<root>
  <document>
    <sentences>
      <sentence id="1">
        <tokens>
           <token id="7">
            <word>founded</word>
            <lemma>found</lemma>
            <CharacterOffsetBegin>72</CharacterOffsetBegin>
            <CharacterOffsetEnd>79</CharacterOffsetEnd>
            <POS>VBN</POS>
            <NER>O</NER>
          </token>
          <token id="8">
            <word>in</word>
            <lemma>in</lemma>
            <CharacterOffsetBegin>80</CharacterOffsetBegin>
            <CharacterOffsetEnd>82</CharacterOffsetEnd>
            <POS>IN</POS>
            <NER>O</NER>
          </token>
          <token id="9">
            <word>1891</word>
            <lemma>1891</lemma>
            <CharacterOffsetBegin>83</CharacterOffsetBegin>
            <CharacterOffsetEnd>87</CharacterOffsetEnd>
            <POS>CD</POS>
            <NER>DATE</NER>
            <NormalizedNER>1891</NormalizedNER>
            <Timex tid="t1" type="DATE">1891</Timex>
          </token>
          <token id="10">
            <word>.</word>
            <lemma>.</lemma>
            <CharacterOffsetBegin>87</CharacterOffsetBegin>
            <CharacterOffsetEnd>88</CharacterOffsetEnd>
            <POS>.</POS>
            <NER>O</NER>
          </token>
        </tokens>
      </sentence>
    </sentences>
  </document>
</root>

现在我在 Form1 上放置了一个 Datagrid 并添加了以下代码:

Dim ds As DataSet = New DataSet()

ds.ReadXml("input.txt.xml")

With Me.DataGridView1

    .DataSource = ds

    .DataMember = "token"

End With

它看起来很棒。我可以看到我的 XML 中的所有标记都填充了 Datagrid 的行和列。

但我不想要数据网格中的数据。我只希望它在数据表中....

 Dim dt As DataTable = New DataTable()


        dt.ReadXml("input.txt.xml")

那么我可以发出像 .DataMember = "token" 这样的命令还是需要将其复制到新的数据表中?

谢谢

4

1 回答 1

0

I did it via a dataview:

Dim myDT As DataTable
Dim myDV As DataView

myDV = ds.Tables(4).DefaultView
myDT = myDV.ToTable

If anyone knows how to go directly or replace the (4) with "token" - because it is the 4th table in the dataset then let me know.

于 2013-06-12T09:16:37.493 回答