simplexml_load_string( )函数问题
我在程序里面写了下面的语句,目的是想将$data转化为php数组,$content是一个xml格式字符串$data=simplexml_load_string($cont...
我在程序里面写了下面的语句,目的是想将$data转化为php数组,$content是一个xml格式字符串
$data = simplexml_load_string( $content );
foreach ( $data as $key => $value ) {
$mydata [$key] = strval ( $value );
}
经过测试,发现我的$data的内容格式如下:
["Event"] => object(SimpleXMLElement)#19 (0) {}
["EventKey"] => object(SimpleXMLElement)#20 (0) {}
["ScanCodeInfo"] => object(SimpleXMLElement)#21 (2) {//这个地方是一个双层的标签元素
["ScanType"] => object(SimpleXMLElement)#22 (0) {}
["ScanResult"] => object(SimpleXMLElement)#23 (0) {}
}
但是$mydata中格式为
s:5:"Event";s:16:"scancode_waitmsg";
s:8:"EventKey";s:13:"rselfmenu_0_0";
s:12:"ScanCodeInfo";s:2:"\n\n";
也就是说ScanCodeInfo的值为两个换行,就是没有读到子标签,而我希望得到是具体ScanType,ScanResult的值,我该怎么办呢,我尝试了$data->ScanCodeInfo->ScanType和$data->ScanCodeInfo->ScanResult两种方法,但是都不行,无法读取值,我是php新手,哪位大神帮助下,谢谢啦 展开
$data = simplexml_load_string( $content );
foreach ( $data as $key => $value ) {
$mydata [$key] = strval ( $value );
}
经过测试,发现我的$data的内容格式如下:
["Event"] => object(SimpleXMLElement)#19 (0) {}
["EventKey"] => object(SimpleXMLElement)#20 (0) {}
["ScanCodeInfo"] => object(SimpleXMLElement)#21 (2) {//这个地方是一个双层的标签元素
["ScanType"] => object(SimpleXMLElement)#22 (0) {}
["ScanResult"] => object(SimpleXMLElement)#23 (0) {}
}
但是$mydata中格式为
s:5:"Event";s:16:"scancode_waitmsg";
s:8:"EventKey";s:13:"rselfmenu_0_0";
s:12:"ScanCodeInfo";s:2:"\n\n";
也就是说ScanCodeInfo的值为两个换行,就是没有读到子标签,而我希望得到是具体ScanType,ScanResult的值,我该怎么办呢,我尝试了$data->ScanCodeInfo->ScanType和$data->ScanCodeInfo->ScanResult两种方法,但是都不行,无法读取值,我是php新手,哪位大神帮助下,谢谢啦 展开
1个回答
展开全部
我需要你xml格式的内容。
给个参考给你吧!这是我的xml数据,我想获取key节点,orig节点的值
1 2 3 4 5 6 7 8 9 10 11 12 13 | < dict num = "219" id = "219" name = "219" > < key >你好</ key > < pos ></ pos > < acceptation >Array;Array;Array;</ acceptation > < sent > < orig >Haven't seen you for a long time. How are you?</ orig > < trans >多日不见了,你好吗?</ trans > </ sent > < sent > < orig >Haven't seen you for a long time. How are you?</ orig > < trans >多日不见了,你好吗?</ trans > </ sent > </ dict > |
$xmldata = simplexml_load_string($data);//$data就是这个xml
key节点:$xmldata->key
第一个orig节点:$xmldata->sent[0]->orig
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询