【问题标题】:How can I convert this data to .CSV from this deeply nested XML file?如何将此数据从这个深度嵌套的 XML 文件转换为 .CSV?
【发布时间】:2015-12-14 13:44:33
【问题描述】:

我有一个 105MB 大的大型字典 XML 文件。下面是它的嵌套示例:

    <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE lexdataset
  SYSTEM "CollexML.dtd">
 <superentry id="u583c10bfdbd326ba.31865a51.12110e76de1.-326"><entry publevel="2" id="u583c10bfdbd326ba.31865a51.12110e76de1.-325"><hwblk><hwgrp><hwunit><hw>aah</hw></hwunit></hwgrp></hwblk><datablk><gramcat publevel="2"><pospgrp><pospunit><posp value="verb"/></pospunit></pospgrp><sensecat publevel="2"><defgrp><defunit><def>exclaim in pleasure</def></defunit></defgrp></sensecat></gramcat></datablk></entry></superentry>
<superentry><entry publevel="2"><hwblk><hwgrp><hwunit form="inflected"><hw>aahed</hw></hwunit></hwgrp></hwblk><datablk><xrefgrp><xrefunit publevel="2"><xref superentryid="u583c10bfdbd326ba.31865a51.12110e76de1.-326" xrefid="u583c10bfdbd326ba.31865a51.12110e76de1.-325"><xrhw publevel="2">aah</xrhw></xref></xrefunit></xrefgrp></datablk></entry></superentry>
<superentry><entry publevel="2"><hwblk><hwgrp><hwunit form="inflected"><hw>aahing</hw></hwunit></hwgrp></hwblk><datablk><xrefgrp><xrefunit publevel="2"><xref superentryid="u583c10bfdbd326ba.31865a51.12110e76de1.-326" xrefid="u583c10bfdbd326ba.31865a51.12110e76de1.-325"><xrhw publevel="2">aah</xrhw></xref></xrefunit></xrefgrp></datablk></entry></superentry>
<superentry><entry publevel="2"><hwblk><hwgrp><hwunit form="inflected"><hw>aahs</hw></hwunit></hwgrp></hwblk><datablk><xrefgrp><xrefunit publevel="2"><xref superentryid="u583c10bfdbd326ba.31865a51.12110e76de1.-326" xrefid="u583c10bfdbd326ba.31865a51.12110e76de1.-325"><xrhw publevel="2">aah</xrhw></xref></xrefunit></xrefgrp></datablk></entry></superentry>
</lexdataset>

对我来说,它很难阅读,我不确定如何输出它。有人有什么想法吗?

我想做的就是提取这些东西: 这个词本身 定义, 一个词是变形还是派生

【问题讨论】:

  • 你使用什么编程语言?
  • 我已经尝试过使用 XQuery,但现在无法真正理解它。否则,我愿意接受任何适合此类文件的语言

标签: xml csv tsql


【解决方案1】:

我建议你试试 BaseX 的 CSV 模块。更多详情:http://docs.basex.org/wiki/CSV_Module

【讨论】:

    【解决方案2】:

    对于通过搜索遇到此问题的任何人,我最终只是使用以下语法将行插入到 MS SQL Server 中的新表中:

    select
     WordID         = IDENTITY(INT,1,1),
     a.b.value('(hwblk/hwgrp/hwunit/hw/text())[1]', 'nvarchar(250)') as [Word],
     a.b.value('(datablk/xrefgrp/xrefunit/xref/xrhw/text())[1]', 'nvarchar(250)') as [Derivation],
     a.b.value('(datablk/gramcat/sensecat/defgrp/defunit/def/text())[1]', 'nvarchar(250)') as [Definition],
     a.b.value('(datablk/gramcat/pospgrp/pospunit/posp/@value)[1]', 'nvarchar(30)') as [POSP],
     a.b.value('(hwblk/hwgrp/hwunit/@form)[1]', 'nvarchar(30)') as [Form],
     a.b.value('(@publevel)', 'int') as [Ambiguity]
     into Dictionary
    
    from [dbo].[DictionaryXML] c 
    cross apply c.xmldata.nodes('lexdataset/superentry/entry') a(b)
    

    【讨论】:

      猜你喜欢
      • 2020-02-21
      • 1970-01-01
      • 2019-02-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-09
      • 1970-01-01
      • 2022-09-30
      相关资源
      最近更新 更多