- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如何将包含 600MB xml 文件(超过 300,000 个“<”abc:ABCRecord">”)的 50MB zip 文件放入 mysql 数据表中? xml 文件本身具有以下结构:
<?xml version='1.0' encoding='UTF-8'?>
<abc:ABCData xmlns:abc="http://www.abc-example.com" xmlns:xyz="http:/www.xyz-example.com">
<abc:ABCHeader>
<abc:ContentDate>2015-08-15T09:03:29.379055+00:00</abc:ContentDate>
<abc:FileContent>PUBLISHED</abc:FileContent>
<abc:RecordCount>310598</abc:RecordCount>
<abc:Extension>
<xyz:Sources>
<xyz:Source>
<xyz:ABC>5967007LIEEXZX4LPK21</xyz:ABC>
<xyz:Name>Bornheim Register Centre</xyz:Name>
<xyz:ROCSponsorCountry>NO</xyz:ROCSponsorCountry>
<xyz:RecordCount>398</xyz:RecordCount>
<xyz:ContentDate>2015-08-15T05:00:02.952+02:00</xyz:ContentDate>
<xyz:LastAttemptedDownloadDate>2015-08-15T09:00:01.885686+00:00</xyz:LastAttemptedDownloadDate>
<xyz:LastSuccessfulDownloadDate>2015-08-15T09:00:02.555222+00:00</xyz:LastSuccessfulDownloadDate>
<xyz:LastValidDownloadDate>2015-08-15T09:00:02.555222+00:00</xyz:LastValidDownloadDate>
</xyz:Source>
</xyz:Sources>
</abc:Extension>
</abc:ABCHeader>
<abc:ABCRecords>
<abc:ABCRecord>
<abc:ABC>5967007LIEEXZX4LPK21</abc:ABC>
<abc:Entity>
<abc:LegalName>REGISTERENHETEN I Bornheim</abc:LegalName>
<abc:LegalAddress>
<abc:Line1>Havnegata 48</abc:Line1>
<abc:City>Bornheim</abc:City>
<abc:Country>NO</abc:Country>
<abc:PostalCode>8900</abc:PostalCode>
</abc:LegalAddress>
<abc:HeadquartersAddress>
<abc:Line1>Havnegata 48</abc:Line1>
<abc:City>Bornheim</abc:City>
<abc:Country>NO</abc:Country>
<abc:PostalCode>8900</abc:PostalCode>
</abc:HeadquartersAddress>
<abc:BusinessRegisterEntityID register="Enhetsregisteret">974757873</abc:BusinessRegisterEntityID>
<abc:LegalForm>Organisasjonsledd</abc:LegalForm>
<abc:EntityStatus>Active</abc:EntityStatus>
</abc:Entity>
<abc:Registration>
<abc:InitialRegistrationDate>2014-06-15T12:03:33.000+02:00</abc:InitialRegistrationDate>
<abc:LastUpdateDate>2015-06-15T20:45:32.000+02:00</abc:LastUpdateDate>
<abc:RegistrationStatus>ISSUED</abc:RegistrationStatus>
<abc:NextRenewalDate>2016-06-15T12:03:33.000+02:00</abc:NextRenewalDate>
<abc:ManagingLOU>59670054IEEXZX44PK21</abc:ManagingLOU>
</abc:Registration>
</abc:ABCRecord>
<abc:ABCRecord>
<abc:ABC>5967007LIE45ZX4MHC90</abc:ABC>
<abc:Entity>
<abc:LegalName>SUNNDAL HOSTBANK</abc:LegalName>
<abc:LegalAddress>
<abc:Line1>Sunfsalsvegen 15</abc:Line1>
<abc:City>SUNNDALSPRA</abc:City>
<abc:Country>NO</abc:Country>
<abc:PostalCode>6600</abc:PostalCode>
</abc:LegalAddress>
<abc:HeadquartersAddress>
<abc:Line1>Sunndalsvegen 15</abc:Line1>
<abc:City>SUNNDALSPRA</abc:City>
<abc:Country>NO</abc:Country>
<abc:PostalCode>6600</abc:PostalCode>
</abc:HeadquartersAddress>
<abc:BusinessRegisterEntityID register="Foretaksregisteret">9373245963</abc:BusinessRegisterEntityID>
<abc:LegalForm>Hostbank</abc:LegalForm>
<abc:EntityStatus>Active</abc:EntityStatus>
</abc:Entity>
<abc:Registration>
<abc:InitialRegistrationDate>2014-06-26T15:01:02.000+02:00</abc:InitialRegistrationDate>
<abc:LastUpdateDate>2015-06-27T15:02:39.000+02:00</abc:LastUpdateDate>
<abc:RegistrationStatus>ISSUED</abc:RegistrationStatus>
<abc:NextRenewalDate>2016-06-26T15:01:02.000+02:00</abc:NextRenewalDate>
<abc:ManagingLOU>5967007LIEEXZX4LPK21</abc:ManagingLOU>
</abc:Registration>
</abc:ABCRecord>
</abc:ABCRecords>
</abc:ABCData>
mysql 表需要是什么样子以及如何实现这一点?目标是让表中包含所有 abc 标记的内容。此外,每天都会通过下载链接提供一个新的 zip 文件,并且每天都会更新该表。 zip 文件以以下结构命名:“20150815-XYZ-concatenated-file.zip”。一步一步的提示会很棒吗?我试过这个:Importing XML file with special tags & namespaces <abc:xyz> in mysql截至目前,但还没有完成工作!
根据下面的 ThW 解释,我现在已经完成了以下操作:
<?php
// open input
$reader = new XMLReader();
$reader->open('./xmlreader.xml');
// open output
$output = fopen('./xmlreader.csv', 'w');
fputcsv($output, ['id', 'name']);
$xmlns = [
'a' => 'http://www.abc-example.com'
];
// prepare DOM
$dom = new DOMDocument;
$xpath = new DOMXpath($dom);
foreach ($xmlns as $prefix => $namespaceURI) {
$xpath->registerNamespace($prefix, $namespaceURI);
}
// look for the first record element
while (
$reader->read() &&
(
$reader->localName !== 'ABCRecord' ||
$reader->namespaceURI !== $xmlns['a']
)
) {
continue;
}
// while you have an record element
while ($reader->localName === 'ABCRecord') {
if ($reader->namespaceURI === 'http://www.abc-example.com') {
// expand record element node
$node = $reader->expand($dom);
// fetch data and write it to output
fputcsv(
$output,
[
$xpath->evaluate('string(a:ABC)', $node),
$xpath->evaluate('string(a:Entity/a:LegalName)', $node)
]
);
}
// move to the next record sibling
$reader->next('ABCRecord');
}
这是正确的吗?!我在哪里可以找到输出?!以及如何获取 mysql 中的输出。抱歉我的菜鸟问题,这是我第一次这样做......
$dbHost = "localhost";
$dbUser = "root";
$dbPass = "password";
$dbName = "new_xml_extract";
$dbConn = mysqli_connect($dbHost, $dbUser, $dbPass, $dbName);
$delete = $dbConn->query("TRUNCATE TABLE `test_xml`");
....
$sql = "INSERT INTO `test_xml` (`.....`, `.....`)" . "VALUES ('". $dbConn->real_escape_string($.....) ."', '".$dbConn->real_escape_string($.....)."')";
$result = $dbConn->query($sql);
}
最佳答案
MySQL 不知道您的 XML 结构。虽然它可以直接导入简单、格式良好的 XML 结构,但您需要自己转换更复杂的结构。您可以生成 CSV、SQL 或(支持的)XML。
对于像这样的大文件,XMLReader 是最好的 API。首先创建一个实例并打开文件:
$reader = new XMLReader();
$reader->open('php://stdin');
您正在使用命名空间,因此我建议为它们定义一个映射数组:
$xmlns = [
'a' => 'http://www.abc-example.com'
];
可以使用与 XML 文件中相同的前缀/别名,但您也可以使用自己的前缀/别名。
接下来遍历XML节点,直到找到第一个记录元素节点:
while (
$reader->read() &&
($reader->localName !== 'ABCRecord' || $reader->namespaceURI !== $xmlns['a'])
) {
continue;
}
您需要比较本地名称(不带命名空间前缀的标记名称)和命名空间 URI。这样您的编程就不会依赖于 XML 文件中的实际前缀。
找到第一个节点后,可以遍历到具有相同本地名称的下一个兄弟节点。
while ($reader->localName === 'ABCRecord') {
if ($reader->namespaceURI === 'http://www.abc-example.com') {
// read data for the record ...
}
// move to the next record sibling
$reader->next('ABCRecord');
}
您可以使用 XMLReader 来读取记录数据,但使用 DOM 和 XPath 表达式会更容易。 XMLReader可以将当前节点扩展为DOM节点。因此,准备一个 DOM 文档,为其创建一个 XPath 对象并注册 namespace 。展开节点会将节点及其所有后代加载到内存中,但不会加载父节点或兄弟节点。
$dom = new DOMDocument;
$xpath = new DOMXpath($dom);
foreach ($xmlns as $prefix => $namespaceURI) {
$xpath->registerNamespace($prefix, $namespaceURI);
}
while ($reader->localName === 'ABCRecord') {
if ($reader->namespaceURI === 'http://www.abc-example.com') {
$node = $reader->expand($dom);
var_dump(
$xpath->evaluate('string(a:ABC)', $node),
$xpath->evaluate('string(a:Entity/a:LegalName)', $node)
);
}
$reader->next('ABCRecord');
}
DOMXPath::evaluate()
允许您使用 Xpath 表达式从 DOM 获取标量值或节点列表。
fputcsv()
将数据写入 CSV 变得非常容易。
放在一起:
// open input
$reader = new XMLReader();
$reader->open('php://stdin');
// open output
$output = fopen('php://stdout', 'w');
fputcsv($output, ['id', 'name']);
$xmlns = [
'a' => 'http://www.abc-example.com'
];
// prepare DOM
$dom = new DOMDocument;
$xpath = new DOMXpath($dom);
foreach ($xmlns as $prefix => $namespaceURI) {
$xpath->registerNamespace($prefix, $namespaceURI);
}
// look for the first record element
while (
$reader->read() &&
(
$reader->localName !== 'ABCRecord' ||
$reader->namespaceURI !== $xmlns['a']
)
) {
continue;
}
// while you have an record element
while ($reader->localName === 'ABCRecord') {
if ($reader->namespaceURI === 'http://www.abc-example.com') {
// expand record element node
$node = $reader->expand($dom);
// fetch data and write it to output
fputcsv(
$output,
[
$xpath->evaluate('string(a:ABC)', $node),
$xpath->evaluate('string(a:Entity/a:LegalName)', $node)
]
);
}
// move to the next record sibling
$reader->next('ABCRecord');
}
输出:
id,name
5967007LIEEXZX4LPK21,"REGISTERENHETEN I Bornheim"
5967007LIE45ZX4MHC90,"SUNNDAL HOSTBANK"
关于php - 如何将 50MB 的 zip 文件和 600MB 的 xml 文件放入 mysql 数据表中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32112985/
我有一个本地存储库,有一个大文件被意外添加到其中。现在,即时通讯几乎落后了100次提交。当我尝试推送到GitHub时,它给了我一个错误。 我需要做任何我需要做的事情,以便能够推送此存储库的其余部分。
我正在尝试分配内存NSImage*originalLocationImage; NSURL *fileURL = [NSURL fileURLWithPath:originalLocation];//
我如何以及在何处可以编辑CDH4.7中的输入拆分大小,默认情况下为64 MB,但我想将其称为1MB,因为我的MR作业运行缓慢并且我想提高MR作业的速度。我想需要编辑cor-site属性IO.file.
我创建了一个 DLL,其中包含一个从 C# 代码调用的 JNI 函数。作为长时间运行的 GUI 应用程序的 C# 应用程序多次调用该函数。 我的 JNI 函数调用 JNI_GetCreatedJava
运行 TestDFSIO 后,我得到了以下指标: 2019-04-30 09:50:35,790 INFO fs.TestDFSIO: Date & time: Tue Apr
我正在测试连接到 Xcode 5.1.1 的运行 iOS 7.1 的 iPhone 4。我不明白为什么当仪器显示我的应用程序仅使用几兆字节并且有大量可用内存时我会收到内存警告甚至崩溃(见附件)。有什么
我有一个假设的值数据库,每个值的大小为 4 个字节(即 4,000,000,000)。所有值都存在于数据库中,因此它以 0 开头,以最大的 4 字节数字结尾。 只有一次,我想通过将 1 到 10000
我有一个字符串元组的 python 列表,格式如下:lst = [('xxx', 'yyy'), ...etc]。该列表包含大约 8154741 个元组。我使用了一个分析器,它说该列表占用大约 500
我需要每秒发送 1,00,000 批记录。我在实验后得到的是 azure event hub 的事件限制为 10,00,000 个字节。我的每条记录有 145 字节,我必须发送的总记录是 1,00,0
HDFS块大小默认为128 MB(来源:https://hadoop.apache.org/docs/r2.9.0/hadoop-project-dist/hadoop-hdfs/hdfs-defau
我需要每秒发送 1,00,000 批记录。我在实验后得到的是 azure event hub 的事件限制为 10,00,000 个字节。我的每条记录有 145 字节,我必须发送的总记录是 1,00,0
我正在 Linux 机器上运行 Jboss EAP 服务器 6.1。分配的堆内存如下。 JAVA_OPTS="-Xms2048m -Xmx2048m -XX:MaxPermSize=256m -Dja
我最近提出并解决了一个关于将大于 2 MB 的 .PDF 文件作为 BLOBS 上传到 MySQL 数据库的问题。我不得不更改我的 php.ini 文件中的一些设置和 MySQL 的最大数据包设置。然
我需要创建一个文本文件(字母数字),其大小(精确或接近)以 MB 为单位等于我输入的数字,例如 1 MB。我试图生成一个字符串,认为一个字符是 16 位或 2 字节,所以:1KB = 1024 字节
我已经阅读了很多有关通过设置 yarn.scheduler.maximum-allocation-mb 来解决此类问题的内容,我已将其设置为 2gb,因为我当前正在运行 select count(*)
这个问题在这里已经有了答案: this exceeds GitHub's file size limit [duplicate] (3 个回答) 1年前关闭。 核心程序崩溃数据。 我不知道核心文件是从
我已经建立了一个 Electron 应用程序,并使用 Electron 打包程序对其进行了打包。我制作了238MB的Windows bundle 包,而Linux版本是450 MB。我将其与也是 El
这个问题在这里已经有了答案: Generate an integer that is not among four billion given ones (38 个答案) 关闭 9 年前。 Give
我的 Meteor 应用程序获取一个 CSV 文件,使用 Baby Parse(Papa Parse for server)对其进行解析,并将数据插入到 MongoDB 集合中。 每个 CSV 行都作
Amazon SES 有 10 MB 的文件限制 我的问题是 有没有其他方法可以发送超过 10 MB 的文件? 最佳答案 这是一个硬限制。 您需要做的是包含您当前包含在电子邮件中的 Assets 的
我是一名优秀的程序员,十分优秀!