简体   繁体   English

如何将大型 xml 文件转换为 csv 格式?

[英]how to convert large xml files to csv format?

I tried it online but the size is too big.我在网上试过,但是尺寸太大了。 i want to convert large xml files nearly 50 mb to csv format which is unable to be done at all neither online nor in any software.我想将近 50 mb 的大型 xml 文件转换为 csv 格式,无论是在线还是在任何软件中都无法完成。 i wanna know what should be the best idea to convert them thanks我想知道转换它们的最佳主意应该是什么,谢谢

XML is a standard format for content. XML 是内容的标准格式。 I would approach this as two steps.我将这分为两个步骤。 Google "parse xml" and "generate csv".谷歌“解析 xml”和“生成 csv”。 Your program will implement both and then you'll be done.您的程序将实现两者,然后您就完成了。 There are a number of options.有多种选择。

Also, consider using a program that reads XML files and uses XSLT files to do the transformation.此外,请考虑使用读取 XML 文件并使用 XSLT 文件进行转换的程序。 If you pop over to W3schools there is a tutorial about XML and XLST: w3schools xsl tutorial .如果您访问 W3schools,则有一个关于 XML 和 XLST 的教程: w3schools xsl 教程 The XSL usually is used to generate HTML from an XML file, but an HTML file is just text. XSL 通常用于从 XML 文件生成 HTML,但 HTML 文件只是文本。 You could output the CSV directly.您可以直接输出 CSV。 (There are some issues with CSV that cause some headaches, such as punctuation including commas and double quotes that can mess up the CSV, but there are workarounds. (CSV 有一些问题会导致一些令人头疼的问题,例如包含逗号和双引号的标点符号可能会弄乱 CSV,但有一些解决方法。

This snippet is an example of generating a two column CSV file pulling out Title and Artist from an XML file containing those tags.此代码段是生成两列 CSV 文件的示例,从包含这些标签的 XML 文件中提取标题和艺术家。 The second line is the header line for CSV and the rest of the template forms each subsequent line in the CSV file:第二行是 CSV 的标题行,模板的其余部分构成了 CSV 文件中的每个后续行:

<xsl:template match="/">
Title,Artist\n
<xsl:for-each select="catalog/cd">
  <xsl:value-of select="title"/>,<xsl:value-of select="artist"/>\n
</xsl:for-each>
</xsl:template>

The \\n imbedded in the template needs to be whatever is the new line character in the processor you choose.嵌入在模板中的 \\n 需要是您选择的处理器中的换行符。 Substitute the correct tag names for your application.为您的应用程序替换正确的标签名称。 The Saxan and Xalan are two projects that implement the process. Saxan 和 Xalan 是实施该流程的两个项目。 XSLTproc XSLTproc is available here is a command line tool. XSLTproc XSLTproc 在这里是一个命令行工具。 If you do this in a browser you could implement the html table syntax from the example at w3schools.如果您在浏览器中执行此操作,您可以实现 w3schools 示例中的 html 表语法。

Check conversiontools.io .检查converttools.io

Online XML to CSV Converter that supports conversion of XML files up to 20 Gb !在线 XML 到 CSV 转换器,支持最大20 Gb的 XML 文件的转换!

The same large 20 Gb XML can be converted using their XML to Excel Converter , and it will split the result to several .xlsx files based on the Excel limits (number of rows limit).同样大的 20 Gb XML 可以使用他们的XML to Excel Converter 进行转换,它会根据 Excel 限制(行数限制)将结果拆分为多个 .xlsx 文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM