我正在开发一个项目,该项目将通过表单中的textarea输入提取XML数据,然后提取数据并将其丢入数据库.我在XML的根域中遇到属性错误(每次都是相同的模式,但具有不同的值).如果我删除这些属性它工作正常,但我不想每次我去发送数据到脚本时删除这些属性.
这是我正在使用的数据和代码的示例(给我错误的部分):
<raid generatedFrom="HeadCount" version="1.7.4">
--snip--
</raid>
Run Code Online (Sandbox Code Playgroud)
如果我这样发布数据,我会收到如下错误:
Warning: SimpleXMLElement::__construct() [function.SimpleXMLElement---construct]: Entity: line 1: parser error : AttValue: " or ' expected in /home/content/g/V/i/gViscardi/html/guilds/sanctum/headcount.php on line 13
Warning: SimpleXMLElement::__construct() [function.SimpleXMLElement---construct]: <raid generatedFrom=\"HeadCount\" version=\"1.7.4\"> in /home/content/g/V/i/gViscardi/html/guilds/sanctum/headcount.php on line 13
Warning: SimpleXMLElement::__construct() [function.SimpleXMLElement---construct]: ^ in /home/content/g/V/i/gViscardi/html/guilds/sanctum/headcount.php on line 13
Warning: SimpleXMLElement::__construct() [function.SimpleXMLElement---construct]: Entity: line 1: parser error : attributes construct error in /home/content/g/V/i/gViscardi/html/guilds/sanctum/headcount.php on line 13
Warning: SimpleXMLElement::__construct() [function.SimpleXMLElement---construct]: <raid generatedFrom=\"HeadCount\" version=\"1.7.4\"> in /home/content/g/V/i/gViscardi/html/guilds/sanctum/headcount.php on line 13
Warning: SimpleXMLElement::__construct() [function.SimpleXMLElement---construct]: ^ in …Run Code Online (Sandbox Code Playgroud) 这类似于我发布的一个问题,但我已经扩展了,因为这必须是可解决的.
我正在尝试从此RSS Feed访问评级和viewCount.现在,这些命名空间用yt:和gd: - 但是命名空间引用是来自youtube的feed的404,所以它似乎失败了.请帮忙吗?
我正在尝试使用: -
$ytFeed->children('http://gdata.youtube.com/schemas/2007')->statistics->attributes('viewCount'));
Run Code Online (Sandbox Code Playgroud)
但它失败了...它确实像通常那样工作,例如我可以访问媒体:用
$ytFeed->children('http://search.yahoo.com/mrss/')->group->category);
Run Code Online (Sandbox Code Playgroud)
这是原始RSS,请查看这些节点的底部: -
<?xml version='1.0' encoding='UTF-8'?>
<entry xmlns='http://www.w3.org/2005/Atom' xmlns:media='http://search.yahoo.com/mrss/' xmlns:gd='http://schemas.google.com/g/2005' xmlns:yt='http://gdata.youtube.com/schemas/2007'>
<id>http://gdata.youtube.com/feeds/api/videos/tDJFDsZFw2E</id>
<published>2009-03-02T07:02:49.000Z</published>
<updated>2011-07-19T06:57:29.000Z</updated>
<category scheme='http://schemas.google.com/g/2005#kind' term='http://gdata.youtube.com/schemas/2007#video' />
<category scheme='http://gdata.youtube.com/schemas/2007/categories.cat' term='Music' label='Music' />
<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='Other Lives' />
<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='Jesse Tabish' />
<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='Jenny Hsu' />
<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='Jupiter Hotel' />
<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='Portland' />
<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='music' />
<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='band' />
<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='interview' />
<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='mf magazine' />
<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='fashion' />
<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='hotel …Run Code Online (Sandbox Code Playgroud) 我有一个很大的问题(至少对我而言;))使用SimpleXML解析器.错误是:
Warning: simplexml_load_file(): file.meta:16: parser error : StartTag: invalid element name in index.php on line 89
Warning: simplexml_load_file(): <335> in index.php on line 89
Warning: simplexml_load_file(): ^ in index.php on line 89
Warning: simplexml_load_file(): file.meta:18: parser error : expected '>' in index.php on line 89
Warning: simplexml_load_file(): in index.php on line 89 Warning: simplexml_load_file(): ^ in index.php on line 89 Warning: simplexml_load_file(): file.meta:18: parser error : Opening and ending tag mismatch: Sequence line 15 and unparseable in index.php on line …
所以我<div>在xml文件中有一个列表.我正在使用php的simpleXML解析文件
我可以使用以下代码生成所有div的数组:
$divArray = $xmldoc->text->body->children();
Run Code Online (Sandbox Code Playgroud)
但是现在我想在div中通过不同的childNodes(作者,标题,日期)来订购$ divArray.
div看起来像这样.
<div>
<bibl>
<author>
<title>
<date>
</bibl>
</div>
Run Code Online (Sandbox Code Playgroud)
那么我怎么能把$ divArray和<author>or <title>或它排序呢<date>?
谢谢你的帮助.JW
我的代码只是返回以下内容:
致命错误:在第6行的/path/to/xmltest.php中调用未定义的函数SimpleXMLElement()
和代码本身:
<?php
$language_url = "http://www.fakesite.com/api/FAKEAPIKEY/languages.xml";
// Passing the XML
$data = file_get_contents($language_url);
$books = SimpleXMLElement($data);
//-------------------
// Passing a filename
//$books = SimpleXMLElement($language_url, null, true);
?>
Run Code Online (Sandbox Code Playgroud)
当然,这$language_url是有效的,但出于隐私考虑,我对其进行了更改。它位于我尝试运行此脚本的其他站点上。
所以我正在尝试使用我发现的一个类来修复我的电子商务问题.
在华盛顿州,在线商店需要根据送货地址确定税率.
类:
/**
* @author SmallDog
* @contact dustin@smalldo.gs
* @created 01-27-2011
**/
class destinationTax
{
private $dor_url = 'http://dor.wa.gov';
function __construct(){ }
function getTax($addr,$city,$zip)
{
$req = $this->dor_url."/AddressRates.aspx?output=xml&addr=$addr&city=$city&zip=$zip";
return $this->_get_decoded($req);
}
private function _get_decoded($url)
{
$url = urlencode($url);
if($xml = simplexml_load_file($url))
{
switch($xml->attributes()->code)
{
case 0:
// Code 0 means address was perfect
break;
case 1:
$xml->msg = "Warning: The address was not found, but the ZIP+4 was located.";
break;
case 2:
$xml->msg = "Warning: Neither …Run Code Online (Sandbox Code Playgroud) 我有一个简单的XML结构,当解析时会simplexml_load_string生成以下内容:
SimpleXMLElement Object
(
[@attributes] => Array
(
[token] => rs2rglql9c8ztem
)
[attachments] => SimpleXMLElement Object
(
[attachment] => 112979696
)
)
Run Code Online (Sandbox Code Playgroud)
XML结构:
<uploads token="vwl3u75llktsdzi">
<attachments>
<attachment>123456789</attachment>
</attachments>
</uploads>
Run Code Online (Sandbox Code Playgroud)
我可以通过迭代得到唯一真正重要的值“ 123456789”,但这是最喜欢的。有没有一种方法可以直接访问它,最好使用元素名称。
我需要能够理想地获得属性。
当它有一些语法问题时,根本不加载XML文件的想法是什么?今天我在加载定义了错误编码的文件时遇到了问题.它有UTF-16标题,但编码UTF-8.我会理解,如果它无法确定正确的编码,但它会抛出警告,文件被UTF-8编码,所以它确实知道该怎么做......这是一个理论问题.无需提供任何示例或说出我尝试过的内容.我知道如何加载文件.只需encoding="UTF-16"改为encoding="UTF-8"......但为什么会出现这样的问题呢?每一个语法字符是完全一样UTF-8和UTF-16C#库,甚至不关心...
我有这样的Google购物Feed(摘录):
<?xml version="1.0" encoding="utf-8" ?>
<rss version="2.0" xmlns:g="http://base.google.com/ns/1.0">
...
<g:id><![CDATA[Blah]]></g:id>
<title><![CDATA[Blah]]></title>
<description><![CDATA[Blah]]></description>
<g:product_type><![CDATA[Blah]]></g:product_type>
Run Code Online (Sandbox Code Playgroud)
现在,SimpleXML可以读取"标题"和"描述"标签,但它无法读取带有"g:"前缀的标签.
对于这种特定情况,使用"children"函数在stackoverflow上有解决方案.但是我不仅想要阅读Google Shopping XMLs,我还需要它来自结构或名称空间,我对文件一无所知(我以递归方式循环遍历节点作为多维数组).
有没有办法用SimpleXML做到这一点?我可以替换冒号,但我希望能够存储数组并重新组合XML(在这种情况下专门用于Google购物),所以我不想丢失信息.
我有以下XML:
<mobapp>
<form>
<input type="text" name="target" id="target" value="" maxlength="8" required="true" pattern="[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]"/>
<label for="target"> Phone number</label>
<input type="number" name="amount" id="amount" min="0" maxlength="16" required="true"/>
<label for="amount"> Amount to load:</label>
</form>
</mobapp>
Run Code Online (Sandbox Code Playgroud)
当我使用时,simplexml_load_string($theXML)我得到以下内容:
object(SimpleXMLElement)#150 (3) {
["input"]=>
array(2) {
[0] => object(SimpleXMLElement)#146 (1) {
["@attributes"]=> [... removed for brevity ...]
}
[1] => object(SimpleXMLElement)#146 (1) {
["@attributes"]=> [... removed for brevity ...]
}
}
["label"]=>
array(2) {
[0] => [... removed for brevity ...]
[1] => [... removed for brevity ...] …Run Code Online (Sandbox Code Playgroud)