【PHPXML转数组函数_PHP教程】教程文章相关的互联网学习教程文章

用PHP将多个XML提要解析为一个排序的数组【代码】

我想创建一个看起来像这样的可排序列表 > $VAR1 [0],$VAR2 [0] …> $VAR1 [1],$VAR2 [1] … 数据来自多个相同的结构化xml文件:$xmlfile=" <Level1><Level2><Level2Item VAR1="1" VAR2="2" ... /><Level2Item VAR1="4" VAR2="5" ... /><Level2Item VAR1="7" VAR2="8" ... /></Level2> </Level1>";//Extract each item $xml = new SimpleXMLElement($xmlfile); foreach ($xml->Level2[0] as $result) {array_push($VAR1Array, $resu...

c#-将数组数组序列化为单个XML元素【代码】

我有一个领域:public Field[][] fields;我想要一个XML:<Fields><Field x="0" y="0">...</Field><Field x="0" y="1">...</Field>... </Fields>不幸的是,C#XmlSerializer给了我<Fields><ArrayOfField>.... some fields here</ArrayOfField><ArrayOfField>.... some here</ArrayOfField>... </Fields>我该如何实现? 好吧,实际上我不需要坚持使用数组数组.这些字段确实代表2D空间,因此这是自然的选择.字典会序列化我需要的方式吗?解...

c#-将根XML元素反序列化为数组【代码】

我需要将XML中的多个字段保存到不同的数组中.这是我的XML的样子:<Content><Colours><Colour name="Strong Red"><R>255</R> <G>0</G><B>0</B><A>255</A> </Colour></Colours><Textures><Texture name="Character01"><Path>Path/Folder</Path></Texture></Textures> </Content>现在,当< Colours>是我的根,我只将颜色添加到一个数组中. 现在,我想通过同一XML文件添加Textures,然后再添加更多,从而将根目录移动到< Content>. 这是...

C#字节数组XML序列化【代码】

我有一个字节数组public byte[] values;我用数据填充new byte[64];我对其进行序列化,然后得到以下XML部分:<values> AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA== </values>我在SO中找到以下解决方案:[XmlElement("values", DataType = "hexBinary")]public byte[] values;现在,我得到的是与上面相同的XML,只是带有“ 0”而不是“ A”. 当我序列化例如一个Int16 / Int32 / sbyte数...

PHP xmlreader进行数组【代码】

以下测试函数使用PHP的xmlreader读取XML文件,并返回3个值的二维数组(“ id” =键). 您如何编辑代码,以便在数组中也返回用户名键和值? (显示在末尾)ini_set('always_populate_raw_post_data', 'on');function test() {$request = $HTTP_RAW_POST_DATA;error_reporting(E_ERROR | E_WARNING | E_PARSE);$url = "http://site.xml";$reader = new XMLReader();$reader->open($url);;$var = array();$i = 0;$limit = 3;while ($reader-...

XML转换为JSON还是数组? PHP

我在想,如果我可以通过func运行XML来验证XML(相对于模式),然后将XML转换为json以方便对象访问,它可能能够使用和处理XML数据?我如何轻松将XML转换为JSON?解决方法:http://www.ibm.com/developerworks/xml/library/x-xml2jsonphp/

如何将xml标记存储为Java中的数组【代码】

在我的应用程序中,我正在解析一个xml文件.在xml文件中,我有50个同名问题标签,现在我想将所有作为问题命名的标签存储为数组. 在保存的那些标签中,我只希望在文本视图中放置一个问题标签. 如何执行此操作…. pls帮助我…..解决方法:公共类CustomHandler扩展了DefaultHandler {private ArrayList<String> questionList; private boolean questionBuffering; private StringBuilder sb;@Override public void startDocument() throws S...

读取XML文件并写入php数组/文件【代码】

我需要更新我的网站的国家/地区列表,我想自动化该过程.国家列表可以在这里找到http://www.iso.org/iso/country_codes…code_lists.htm //编辑:找不到好的链接…… 我试过这种方式 – http://www.w3schools.com/php/php_xml_parser_expat.asp(PHP XML Expat Parser)然而,这似乎不能很好地工作,因为我很困惑在哪里实际“获取”数据并将其打印到我自己的数组供以后使用. 现在我想用XML DOM尝试一下. 只想与大家核实,如果我有一个简单...

SimpleXMLElement到PHP数组【代码】

参见英文答案 > Recursive cast from SimpleXMLObject to Array 5个变量$d来自file_get_contents函数到URL.$answer = @new SimpleXMLElement($d);下面是print_r($answer)的输出:SimpleXMLElement Object ([Amount] => 2698[Status] => OK[State] => FL[Country] => USA )如何检索每个元素的值并添加到数组?我无法弄清楚.解决方法:$answer可以作为数组使用.如果你想把它放在一个真正的数组中,...

php – SimpleXmlElement和XPath,获取空数组()【代码】

我从谷歌结帐响应中解析XML时遇到了一些麻烦. XML直接来自谷歌服务器,所以XML本身没有问题. 我想掌握所有新订单通知标签 我试过这个,但每次都返回一个空数组().$xml = new SimpleXmlElement($raw_xml); $notifications = $xml->xpath('notifications'); $notifications = $xml->xpath('/notification-history-response/notifications/new-order-notification'); $notifications = $xml->xpath('//new-order-notification');一个XML...

将SOAP XML响应转换为PHP对象或数组【代码】

我正在使用cURL向SOAP服务发送请求,我在POST Body中发送包含参数的XML,作为回应我收到: 网络服务:http://lcbtestxmlv2.ivector.co.uk/soap/book.asmx?WSDL<?xml version="1.0" encoding="UTF-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><SearchResponse xmlns="http://ivecto...

PHP从SimpleXMLElement数组中获取值【代码】

我有这个:[1]=> object(SimpleXMLElement)#6 (1) {["@attributes"]=>array(14) {["name"]=>string(5) "MySQL"["acknowledged"]=>string(1) "1"["comments"]=>string(1) "1"["current_check_attempt"]=>string(1) "1"["downtime"]=>string(1) "0"["last_check"]=>string(19) "2010-05-01 17:57:00"["markdown_filter"]=>string(1) "0"["max_check_attempts"]=>string(1) "3"["output"]=>string(42) "CRITICAL - Socket timeout aft...

php – 使用SimpleXMLElement从对象获取数组【代码】

我在这些对象中获取数组时遇到了一些问题.当我print_r()时,将打印以下代码. $message_object是对象的名称.SimpleXMLElement Object ([header] => SimpleXMLElement Object([responsetime] => 2012-12-22T14:10:09+00:00)[data] => SimpleXMLElement Object([id] => Array([0] => 65233[1] => 65234)[account] => Array([0] => 20992[1] => 20992)[shortcode] => Array([0] => 3255[1] => 3255)[received] => Array([0] => 2012-12-...

将带有属性的php数组转换为XML【代码】

我正在研究一个XML库,它可以从arrays / jsons创建/解析xml.我设法用xml_parser编写解析器(和google help:p)因为SimpleXML对我正在做的事情不够好. 我设法创建了一个看起来像这样的数组:Array ( [flow] => Array([math] => Array([apply] => Array([lt] => Array()[apply] => Array([divide] => Array()[apply] => Array([minus] => Array()))[otherStuff] => 0))[true] => Array()[true_attr] => Array([xsi:type] => SomeStuff...

php – 将XML转换为关联数组【代码】

有没有办法使用Zend Framework和PHP将XML转换为数组?我见过人们使用SimpleXML来做这件事,但我想知道是否有通过Zend Framework的方法. 示例XML,我想转换为数组将是:<library><book><authorFirst>Mark</authorFirst><authorLast>Twain</authorLast><title>The Innocents Abroad</title></book><book><authorFirst>Charles</authorFirst><authorLast>Dickens</authorLast><title>Oliver Twist</title></book> </library>转换后的数组...