simplexml

Change Value of Current Child - SimpleXML PHP

ぐ巨炮叔叔 提交于 2019-12-11 13:03:00
问题 The setup is quite simple. How do you use the children() iterating function of SimpleXML and then modify the value of the current node? Here's a scenario below: <Ad> <Unit>Value</Unit> <Size>Value</Size> <Time>Value</Time> </Ad> I'm trying to use children() and then to assign to the current Child to change "Value" in all of the above nodes. foreach ($parent->children() as $child){ $child= "New Value"; // Proper way to access $child's value without overwriting the entire object??? } Thanks in

Parsing xml with simplexml_load

China☆狼群 提交于 2019-12-11 12:42:10
问题 I am trying to parse an xml but I get a problem while I am trying to fetch image url. My xml is: <entry> <title>The Title</title> <id>http://example.com/post/367327.html</id> <summary>Some extra text</summary> <link rel="enclosure" href="http://example.com/photos/f_0px_30px/image687.jpg" type="image/jpeg" length="" /> </entry> So far I am using the code below to fetch the other data: $url = "http://msdssite.com/feeds/xml/myxml.xml"; $xml = simplexml_load_file($url); foreach($xml->entry as

select first child node of root node in XML file using php

自古美人都是妖i 提交于 2019-12-11 11:54:12
问题 I'm new to XML and have so far managed to obtain the root node of an XML using this in php... function xmlRootNode($xmlfile){ $xml = simplexml_load_string(file_get_contents($xmlfile)); $xml = $xml->getName(); echo $xml; } And what I now want to do is use that root node to find out the name of its child node. For example, a file with the below would output 'food' as the root using the above function. How would I now use that to return its childs name 'fruit'? <food> <fruit> <type>apples</type>

XML Split Node on . value

那年仲夏 提交于 2019-12-11 11:46:34
问题 I've used SO for many years and always found an answer but this time I have got myself well and truly lost. I have an xml file I would like to split the compatbility into well formed xml `<product> <item> <partno>abc123</partno> <Compatbility>model1: 110C, 115C, 117C. model2: 1835C, 1840C. model3: 210C, 215C, 3240C.</Compatbility> </item> </product>` In Compatbility the word model changes with each item entry although the : after model is always there as is the . after each model group.

xpath query on SimpleXML Document - Undefined offset: 0

℡╲_俬逩灬. 提交于 2019-12-11 11:06:34
问题 I'm quite new to SimpleXML and using xpath within it. I wasn't sure whether to post this query within the original posting or here, so I linked to here form the original posting. In working through several test scripts, I came across this posting, and I've been attempting to make one of the accepted answers work. However, when I attempt to use the xpath version of the accepted answer work, I get the error message: Undefined offset: 0 I've tested xpath in other ways, to verify that it is

Create a WS-Security header using SimpleXML?

 ̄綄美尐妖づ 提交于 2019-12-11 10:59:07
问题 I want to create a WSS header to authentificate on secured web services. I can do it using an ugly : $auth = ' <wsse:Security SOAP-ENV:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"> <wsu:Timestamp wsu:Id="Timestamp-28" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"> <wsu:Created>' . $timestamp . '</wsu:Created> <wsu:Expires>' . $timestampExpires . '</wsu:Expires> </wsu:Timestamp

PHP SimpleXML issue

泪湿孤枕 提交于 2019-12-11 08:55:51
问题 I'm trying to get an xml stream by using curl. I've recieved the string with curl but I'm having troubles parsing the xmlstream with SimpleXML. The url im using is http://www.google.com/books/feeds/volumes/fR4vqfywNlgC and it seems to be ignoring the parts containing "dc". Why? 回答1: The dublin core data (at least, I'm assuming that's what the DC prefix means in this case) uses its own namespace. You need to refer to that namespace when retrieving these elements. This can be done using the

Should I use proxies with simplexml_load_file and file_get_contents?

ⅰ亾dé卋堺 提交于 2019-12-11 08:53:14
问题 I'm using simplexml_load_file to get RSS from several websites for a while. Sometimes I get errors from some of these websites and for about 5 days I'm having errors from 2 specific websites. Here are the errors from simplexml_load_file : PHP Warning: simplexml_load_file(http://example.com/feed): failed to open stream: Connection timed out PHP Warning: simplexml_load_file(): I/O warning : failed to load external entity "http://example.com/feed" Here are the errors from file_get_contents : PHP

Read XML dynamic PHP

空扰寡人 提交于 2019-12-11 08:45:41
问题 in my site in PHP I want to read an xml file like this: <?xml version="1.0" standalone="yes"?> <RETURNDATA lang="it-IT" type="COR" xsi:noNamespaceSchemaLocation="http://xmlv5test.travco.co.uk/trlink/schema/CountryRequestV6Rcv.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <MESSAGE>All Countries details and relevant city details</MESSAGE> <DATA COUNTRY_CODE="ABW" CURRENCY_CODE="EUR"> <COUNTRY_NAME>Aruba</COUNTRY_NAME> <CURRENCY_NAME>euro</CURRENCY_NAME> <COUNTRY_CITIES> <CITY_DATA

Limit the number of RSS feed to fetch

时光怂恿深爱的人放手 提交于 2019-12-11 08:35:35
问题 I need help with the code of the RSS reader i'm testing on my site, the script work fine but it show 20 feed and i wanted to limit it to a number i set (like 3 or 6 for example). The code it's this: <?php //Feed URLs $feeds = array( "https://robertsspaceindustries.com/comm-link/rss", ); //Read each feed's items $entries = array(); foreach($feeds as $feed) { $xml = simplexml_load_file($feed); $entries = array_merge($entries, $xml->xpath("//item")); } //Sort feed entries by pubDate usort(