我使用以下代码将数据从 XML 导入到 mySQL。\n有没有办法在使用 PHP 加载 & 之前对其进行编码,而不是从文件中手动更改它?
\n\n这是错误
\n\nWarning: simplexml_load_file() [function.simplexml-load-file]: products.xml:4: parser error : xmlParseEntityRef: no name in ... on line 5\n\nWarning: simplexml_load_file() [function.simplexml-load-file]: <description> DAYLIGHT & LED / SMD Tech</description> in ... on line 5\n\nWarning: simplexml_load_file() [function.simplexml-load-file]: ^ in ... on line 5\n\nWarning: Invalid argument supplied for foreach() in ... on line 8\nRun Code Online (Sandbox Code Playgroud)\n\n这是我的 xml 的示例元素
\n\n<?xml version="1.0" encoding="UTF-8"?>\n<description>\xce\x9d\xce\xad\xce\xb1\xcf\x82 \xce\xb3\xce\xb5\xce\xbd\xce\xb9\xce\xac\xcf\x82 & \xcf\x84\xce\xb5\xcf\x87\xce\xbd\xce\xbf\xce\xbb\xce\xbf\xce\xb3\xce\xaf\xce\xb1\xcf\x82 DAYLIGHT LED / SMD Tech</description>\nRun Code Online (Sandbox Code Playgroud)\n 我想在再次填充之前从我的 xml 文件中删除所有子项(或创建更新,但这似乎更难)。所以我所做的是
$file = "data.xml";
$xml=simplexml_load_file($file);
$teller=0;
foreach( $entries as $entry ) {
foreach ($xml->xpath('//concerts') as $desc) {
if($teller == 0)
{
$lol=$desc->children();
unset($lol);
}
$concert = $desc->addChild( 'concert' );
$concert->addChild( 'artist', array_shift( $entry ) );
$concert->addChild( 'location', array_shift( $entry ) );
$concert->addChild( 'date', array_shift( $entry ) );
$teller++;
}
}
file_put_contents($file, $xml->asXML());
Run Code Online (Sandbox Code Playgroud)
但这并不能消除任何东西,对我做错了什么有什么想法吗?
我从源代码中以 XML 形式返回以下内容:
<content type="application/xml">
<m:properties>
<d:ID>30</d:ID>
<d:Name></d:Name>
<d:ProfileImageUrl>default.png</d:ProfileImageUrl>
<d:ThumbnailUrl>default.png</d:ThumbnailUrl>
<d:FavoriteCount m:type="Edm.Int64">0</d:FavoriteCount>
<d:ViewCount m:type="Edm.Int64">12030</d:ViewCount>
<d:LastMonthViewCount m:type="Edm.Int64">1104</d:LastMonthViewCount>
<d:LastWeekViewCount m:type="Edm.Int64">250</d:LastWeekViewCount>
<d:LastDayViewCount m:type="Edm.Int64">21</d:LastDayViewCount>
<d:CreationDate m:type="Edm.DateTime">2011-03-28T13:46:54.227</d:CreationDate>
<d:Enabled m:type="Edm.Boolean">true</d:Enabled>
<d:UrlSafeName>t-boz</d:UrlSafeName>
<d:LastDayFavoriteCount m:type="Edm.Int64">0</d:LastDayFavoriteCount>
<d:LastWeekFavoriteCount m:type="Edm.Int64">0</d:LastWeekFavoriteCount>
<d:LastMonthFavoriteCount m:type="Edm.Int64">0</d:LastMonthFavoriteCount>
<d:IsOnTour m:type="Edm.Boolean">false</d:IsOnTour>
<d:TodayRank m:type="Edm.Int32">6272</d:TodayRank>
<d:WeekRank m:type="Edm.Int32">6851</d:WeekRank>
<d:MonthRank m:type="Edm.Int32">6915</d:MonthRank>
<d:AllTimeRank m:type="Edm.Int32">7973</d:AllTimeRank>
</m:properties>
</content>
Run Code Online (Sandbox Code Playgroud)
我通过 file_get_contents 检索此内容,然后通过 SIMPLEXMLElement 创建。但是我无法访问内容->属性字段(即 ID、名称、ProfileImageUrl 等)。我从 SIMPLEXMLElement 中看到的所有内容如下:
[content] => SimpleXMLElement Object ( [@attributes] => Array ( [type] => application/xml ) )
Run Code Online (Sandbox Code Playgroud)
关于如何获取这些数据有什么想法吗?
谢谢!
我给出了这个表格:
<item><parameter name="a">3</parameter></item>
Run Code Online (Sandbox Code Playgroud)
是否可以用 SimpleXML 读取“a”?
我已经尝试过 $xml->item->parameter->getName(); 但它只返回“参数”。
提前致谢。
我制作了一些 SimpleXMLObject 并将其转换为数组并内爆它们,但结果不是内爆字符串,而是单独的数组的第一个元素。
更有趣的是,它在我的本地服务器(版本为 5.4.4)中按预期工作,但故障发生在我的 php 版本为 5.3.13 的实时服务器中,这就是我的内爆的样子
$im_data = implode( '#', (array)$sync->datas->data);
Run Code Online (Sandbox Code Playgroud)
目标数组如下:
[datas] => SimpleXMLElement Object
(
[data] => Array
(
[0] => AAzdfAA
[1] => BBdBB
[2] => BBDD
[3] => CCCCzsdfC
)
)
Run Code Online (Sandbox Code Playgroud)
但结果不是 AAzdfAA#BBdBB#BBDD#CCCCzsdfC,而是我的实时服务器中的 AAzdfAA。在我的本地服务器中,它按预期工作:AAzdfAA#BBdBB#BBDD#CCCCzsdfC
我有 SimpleXMLElement 对象看起来像这样
SimpleXMLElement Object (
[report-name] = SimpleXMLElement Object
(
[@attributes] = Array
(
[name] = Raport
)
)
[date-range] = SimpleXMLElement Object
(
[@attributes] = Array
(
[date] = Jan 29, 2014
)
) )
Run Code Online (Sandbox Code Playgroud)
我怎样才能从中获得“日期”值?
好吧,事情是这样的,我正在从我的网页数据库中恢复数据并创建一个 xml,其唯一目的是将该数据导入到我的本地数据库中。我这样做是因为本地数据库中的数据非常具体,我不想用无用的信息填充它,所以我所做的是:
<?php
ini_set( 'default_charset', 'UTF-8' );
$ID = $_GET['ID'];
$personInfo = GetPersonSoftwareByID($ID); //this is a function that i created on my own
//xml section
$domTree = new DOMDocument('1.0', 'UTF-8');
$rootXML = $domTree->createElement( 'XML' );
$rootXML = $domTree->appendChild($rootXML);
$personalSoftware = $domTree->createElement( 'PERSON_SOFTWARE' );
$personalSoftware = $rootXML->appendChild($personalSoftware);
$soft = $domTree->createElement('SOFTWARE');
$level = $domTree->createElement('LEVEL');
$soft->nodeValue = $softwares[software];// here the value is = 'Plant&ID'
$level->nodeValue = $softwares[level];
$soft = $personalSoftware ->appendChild($soft);
$level = $personalSoftware ->appendChild($level);
header('Content-type: text/xml; charset=UTF-8');
header('Content-Disposition: attachment; filename="test.xml");
echo $domTree->saveXML(); …Run Code Online (Sandbox Code Playgroud) xml simplexml character-encoding special-characters domdocument
我无法用 simplexml 解决问题。
我刚刚在带有 apache2 服务器的 aws linux/ubuntu 上设置了一个 ec2 实例并尝试安装商店。
问题:
Fatal error: Call to undefined function XXX\Recovery\Install\simplexml_load_file() in /var/www/XXX/recovery/install/src/Requirements.php on line 104
Run Code Online (Sandbox Code Playgroud)
搜索已知问题。我想出了手动安装的 php 包。检查 phpinfo 和 php -mi 后,假设安装了以下模块:
[PHP Modules]
calendar
Core
ctype
curl
date
dom
exif
fileinfo
filter
ftp
gd
gettext
hash
iconv
json
libxml
mbstring
mcrypt
mysqli
mysqlnd
openssl
pcntl
pcre
PDO
pdo_mysql
Phar
posix
readline
Reflection
session
shmop
SimpleXML
sockets
SPL
standard
sysvmsg
sysvsem
sysvshm
tokenizer
wddx
xml
xmlreader
xmlwriter
xsl
Zend OPcache …Run Code Online (Sandbox Code Playgroud) $xml_data = '<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<ns2:orders xmlns:ns2="http://skt.tmall.business.openapi.spring.service.client.domain">
<ns2:order>
<ordNo>201303285538019</ordNo>
<ordPrdSeq>1</ordPrdSeq>
<addPrdNo>0</addPrdNo>
<addPrdYn>N</addPrdYn>
<ordEmail>test@11street.my</ordEmail>
<clearanceEmail>test@11street.my</clearanceEmail >
<dlvCstType>03</dlvCstType>
<dlvNo>140065055</dlvNo>
<lstDlvCst>0</lstDlvCst>
<lstSellerDscPrc>0</lstSellerDscPrc>
<lstTmallDscPrc>0</lstTmallDscPrc>
<memID>test@11street.my</memID>
<memNo>25879997</memNo>
<ordAmt>0</ordAmt>
<ordCnQty>0</ordCnQty>
<ordDt>04-03-2014 10:40:32</ordDt>
<ordNm>Kil Jun Jeong</ordNm>
<ordOptWonStl>300000</ordOptWonStl>
<ordPayAmt>0</ordPayAmt>
<ordPrtblTel>010-2988-6401</ordPrtblTel>
<ordPrdStat>901</ordPrdStat>
<ordQty>0</ordQty>
<ordTlphnNo>070-7400-3141</ordTlphnNo>
<prdNm>test product name</prdNm>
<prdNo>233607759</prdNo>
<prdStckNo>1532843428</prdStckNo>
<rcvrBaseAddr>50929, Kuala Lumpur, Wilayah Persekutuan Kuala Lumpur
</rcvrBaseAddr>
<rcvrDtlsAddr>jl setia budi </rcvrDtlsAddr>
<rcvrMailNo>156010</rcvrMailNo>
<rcvrNm>Kil Jun Jeong</rcvrNm>
<rcvrTlphn>070-7400-3141</rcvrTlphn>
<selPrc>100000</selPrc>
<sellerDscPrc>0</sellerDscPrc>
<tmallDscPrc>0</tmallDscPrc>
</ns2:order>
</ns2:orders>
';
Run Code Online (Sandbox Code Playgroud)
这是我的 xml,我想解析整个 xml,我尝试使用以下代码
$xml = simplexml_load_string($xml_data);
print_r($xml);
Run Code Online (Sandbox Code Playgroud)
但它返回空对象。
SimpleXMLElement 对象 ( )
我尝试使用childrenxml …
我是第一次使用 SimpleXMLElement,需要在我的 XML 中生成一行,如下所示:
<Product xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
Run Code Online (Sandbox Code Playgroud)
我之前没有将 addAttribute 与命名空间一起使用,并且无法在此处使用正确的语法 - 我已经开始了:
$node = new SimpleXMLElement('< Product ></Product >');
$node->addAttribute("xmlns:", "xsd:", 'http://www.w3.org/2001/XMLSchema-instance');
Run Code Online (Sandbox Code Playgroud)
但无法弄清楚如何使用适当的语法更正此问题以生成所需的输出?
simplexml ×10
php ×8
xml ×6
children ×1
domdocument ×1
fatal-error ×1
implode ×1
namespaces ×1
odata ×1
rest ×1
shopware ×1
xml-parsing ×1