Php 导入带有特殊标记的XML文件&;名称空间<;abc:xyz>;在mysql中
在mysql中导入带有特殊标记和名称空间的XML文件。我正在使用的xml文件的摘录:Php 导入带有特殊标记的XML文件&;名称空间<;abc:xyz>;在mysql中,php,mysql,arrays,xml,Php,Mysql,Arrays,Xml,在mysql中导入带有特殊标记和名称空间的XML文件。我正在使用的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.
<?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>
这就是将所有记录插入表的方式:
for ($i = 0; $i < count($ABC); $i++) {
$ABC = $ABC[$i];
$LegalName = $LegalName[$i];
$RegisterEntityID = $RegisterEntityID[$i];
$LegalForm = $LegalForm[$i];
....
// Inserting in mysql (need to be adjusted accordingly)
...
// and/or echoing for testing
...
}
for($i=0;$i
在一些记录中,我得到了字母“或”。而不是Ø它读ÃØ。。。或者,它在表格中读取和写入而不是Ɔ
iconv()为像这样的外国角色发挥了神奇的作用
因此,您需要在回显或表格插入中用iconv(“UTF-8”、“ISO-8859-1”、“$LegalName”)替换例如$LegalName!干杯 如果希望重置表的整个状态,即每次从头开始,一种简单的方法是在开始插入之前对表运行“truncate”查询 请参见此处的文档: 截断表将从中删除所有现有数据,并重置自动递增字段计数器 关于访问具有特殊字符的XML属性,请参见此处的解决方案:
请你把问题2解释得更清楚一点好吗?关于问题2,它就像。。。如果我第一次运行脚本,mysql表中会有7行,如果我第二次运行脚本,表中会有14行。3次=21行,每条记录3行。因此,记录正在“添加”。但我希望表中的原始记录数与xml文件中的原始记录数相同。最后,我想每天用一个新的xml文件更新mysql表(该文件的数量和条目每天都会变化)?在
foreach()
-循环中回显$result
,看看它能给你带来什么。谢谢Michi。但不幸的是,它没有起作用。如果我在“foreach()”循环中插入“echo$result”,浏览器会返回“1111111”,但mysql表中仍然只有7个条目。不要编辑您的问题使其无效,只需将其删除即可。谢谢Brendan!否决票不是我投的!:-)Truncate有助于更新表。我插入$delete=“TRUNCATE TABLEtest2_xml
”$truncate=$dbConn->query($delete)。。。在foreach()语句之前。你知道为什么会出现第1期(12行中只有7行被插入)吗?!看起来这四个未正确插入的实体在其数据中的某个位置都包含单引号。很可能他们没有正确逃脱。您可以通过回显计算出的查询来验证这一点。也许也值得一试:看看它是否有用。嗨,布伦丹!是的,你说得对。我需要添加真正的_escape_string()。。。比如$sql=“插入test2\u xml
(作者
,标题
,类型
,价格
,发布日期
,说明
)”。“值(“$dbConn->real_escape_string($author)。”、“$dbConn->real_escape_string($title)。”、“$dbConn->real_escape_string($general)。”、“$dbConn->real_escape_string($publish_date)。”、“$dbConn->real_escape_string($description)。”;“。。。我已经在上面编辑过了。现在我只剩下xml标记中的特殊字符了,我还没有解决!特殊角色还有什么问题?嗨,布伦丹!请看我的编辑上面。基本上,我想对这个特殊字符xml文件执行相同的任务
for ($i = 0; $i < count($ABC); $i++) {
$ABC = $ABC[$i];
$LegalName = $LegalName[$i];
$RegisterEntityID = $RegisterEntityID[$i];
$LegalForm = $LegalForm[$i];
....
// Inserting in mysql (need to be adjusted accordingly)
...
// and/or echoing for testing
...
}