SimpleXML Parsing By Attribute Value
I have an existing XML data set and would like to parse it with PHP5 based on the value of an attribute (any attribute!). I don't want to convert all my data from an attribute-heavy structure to a more proper element-based structure if I don't have to because of the javascript I am using on the client side. Listed below is the XML structure and PHP code I have been testing.
My existing data structure looks like this: <gallery> <photos> <photo path = "sunflower01.jpg" width = "500" height = "375" thumbpath = "sunflower01.jpg" thumbwidth = "125" thumbheight = "94"> </photo> </photos> </gallery>
The script is here:
<?php $xml = simplexml_load_file("pictures.xml"); $image = $xml->xpath("/gallery/photos/photo[@path='sunflower01.jpg']"); echo $image[0]->photo@thumbpath; ?>
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Simplexml And Attributes With A Namespace In Front. How Do You Getthe Attribute?
Here's a bit of xml code that works. <?php $string = "<?xml version="1.0" standalone="yes"?> <world> <people xmlns:ss="http://crap"> <person id="5">John Doe</person> <person id="2">Susie Q. Public</person> </people> </world>"; $xml = simplexml_load_string($string); print "<pre>"; print_r($xml); print "</pre>"; foreach($xml->people->person as $p) foreach($p->attributes() as $a =$b) { print "$a =$b<br />"; } // prints out // id =5 // id =2 ?> Now what if I change the first person to this <person ss:id="5">John Doe</person> Anyone know how to get the id? This is a question that is pertinent to an excel .xml file as you'll get lines like this <Cell ss:Index="3">stuff</Cell> btw: there is a guide on ibm that tells you how to do this with php and dom. I'm just wondering if there's a way to do it with simplexml.
Weird Chars When Parsing With SimpleXML
I'm using php-5.0.5-pl3; I've created a collector class which populates itself with DOM's nodes from every object which needs to output data. So, at the end of the process, the collector has every piece of the result in a XML document. After this, I need to process the XML document according to the user document request (HTML, XML, Excel, etc.); to accomplish this, I'm using a SimpleXML to parse every node and reinterpret it. I've successfully accomplish HTML transformation, but I've trouble with Excel because some numeric entities aren't translated properly. For example: Importación (Importación) is translated to Importación Acuática (Acuática) is translated to Acuática España (España) is translated to España .... and so on. Is there any function to translate properly the accuted vocals ?
XML - Sorting By Attribute
I'm not sure whether this is a question about php or xml or what to be honest - a poke in the right direction would be much appreciated... I'm storing news articles in XML format. newsitems.php which contains the XML looks like this; ....
Domxml_new_doc - Can I Add Encoding Attribute?
I've got a question about adding encoding attribute to my DOM XML Document? I'm from Poland and we use extended latin alphabet - I'd like to use iso-8859-2 Polish charset e.g.: <?xml version="1.0" encoding="iso-8859-2"?> is there such posibility in DOM XML?
LDAP And TelephoneNumber Attribute
Anyone have a problem with PHP returning the telephoneNumber attribute empty while all the other attributes return just fine. Someone had the same exact problem on phpbuilder but it was never solved. Apparently it holds true for facsimileTelephoneNumber also. Any ideas?
A '<' Character Cannot Be Used In Attribute 'href', Except Through <[xml]
The following embedded snip it of PHP code won't validate using xhtml 1.0 strict. When validating I get the following error: A '<' character cannot be used in attribute 'href', except through <[xml] Code: href="/_Director/forms.php? <?PHP create_request_query('AskQuestions', 'AskQuestions'); ?>" Any idea what's wrong?
Populating An Auto_increament Attribute
I have just designed a BD. there are companies with auto increament which are integer. When I try to populate it after i tool value from another form and try to insert it into a table i recieve an error! I don't ask the companyID value from user as it is auto increament. Don't tell me to put NULL for that entry as it didn't work as well! Code:
Counting Items In An Array Having X Attribute
I want to randomly select 5 cards from a standard playing card deck and count how many of each suit are returned: [connect] $sql = "SELECT * FROM cards ORDER BY RAND()LIMIT 5"; $result = mysql_query($sql); while($cards = mysql_fetch_array($result)) { $value = $cards["card_value"]; $suit = $cards["card_suit"]; $image = $cards["card_image"]; -------- Using count() within the loop returns a count of 1 since each card can only be of one suit. I tried using something like this: $spades = 0; if($suit='spades') { $spades = $spades+1; } and I tried a foreach statement to count within the loop which always returns a count of 1. Would someone be so kind as to point me in the right direction?
Sort A Group Of Nodes By Attribute? How?
I have the following XML file: <?xml version="1.0" encoding="iso-8859-1"?> <items> <item line="2">all that glitters is gold,</item> <item line="1">Theres a lady thats sure,</item> <item line="3">and she's buying a stairway to heaven</item> </items> To output this code Im using the following PHP: $xmldoc = domxml_open_file('stairway.xml', DOMXML_LOAD_DONT_KEEP_BLANKS); $node = $xmldoc->document_element(); if ($xmldoc->has_child_nodes()) { $node = $node->first_child(); $endwhile = false; while ($endwhile != true) { echo $node->get_content() . "<br />"; if ($node->next_sibling()) { $node = $node->next_sibling(); }else{ $endwhile = true; } } } This does what it supposed to do except I want to ensure that it outputs nodes ordered by 'line' attribute. The obvious answer would be to put them in order in the XML file and the above example is very simple so that you get the point, the real life example however will be much larger and encase anyone put something in the wrong order it would muck up my presentation. How could I adapt my code above to allow my nodes to be sorted? I dont mind the nodes being out of order in the physical file (stairway.xml) but when they are output using my script, I want them to be ordered.
Accept Form Attribute Not Working
I cannot get my accept attribute working properly inside either my form, or my input tag. W3schools says that accept is supposed to go inside the input tag, but msdn says it goes in the form tag. I need it for an upload form I'm making, I want to only allow application/octet-stream type files, so I put this as my opening form tag: <form enctype="multipart/form-data" accept="application/octet-stream" action="{$_SERVER['PHP_SELF']}" method="POST"> But I can still upload music, text files, and movies. What gives?
After I Load An XML File, Can I Sort It By Node Attribute
After loading an xml file, is it possible to sort it by attribute? For example, I have the following xml file: <xml... <diary> <entry date="2005-01-01">I went to the park</entry> <entry date="2005-01-03">Sold the car today</entry> <entry date="2005-01-02">Went for a stroll</entry> </diary> When I go to load this using PHP, I would use some this similar to this: $xmldoc = domxml_open_file('diary.xml', DOMXML_LOAD_DONT_KEEP_BLANKS); $node = $xmldoc->document_element(); Before I go storming through the xml tree outputing along the way, can I sort it by (in this case) date?
Php-4.4.0 And Test.wsf = Error: The Value For The Attribute Is Not Valid: Language
We need to use version php-4.4.0-Win32 because one of the portal software doesn't support version php-5.0.5-Win32. We cannot get the PHP setup part working. Here is the error message: Windows Script Host Script: C:kits est.wsf Line: 3 Char: 11 Error: The value for the attribute is not valid: language Code: 80040049 Source: Windows Script Host Here is the code from the install.txt To test if ActiveScript is working, create a new file, named test.wsf (the extension is very important) and type: <job id="test"> <script language="PHPScript"> $WScript->Echo("Hello World!"); </script> </job> Save and double-click on the file. If you receive a little window saying "Hello World!" you're done. Everything works fine using php-5.0.5-Win32.
SimpleXML
What, besides the new php 5.0 zip package, do I need to get SimpleXML to work on my testing server? The docs say to copy libxml2.dll to the system32 directory but I can't find this dll anywhere in the binary package (or anywhere else for that matter). I'm running IIS 6.0 fwiw.
Using SimpleXML
I have started using SimpleXML and can do most things, but there are a couple of things that I can't seem to figure out. Currently, I can: 1. Open & load an XML file 2. Manually parse the XML file 3. Search the XML file using XPath 4. Make changes to existing nodes (values) However, I can't seem to be able to: 1. Add a new node / element. 2. Save my changes back to the XML file Am I missing something, or are these things that currently cannot be done with SimpleXML?
Valid XML For SimpleXML
I'm trying to use SimpleXML but I've run into a conundrum. Every day an XML file is generated that this script grabs and manipulates. How can I check that the XML has no problems before creating my SimpleXMLelement object. Here's what I mean: // this is the code in question: $file_topstory = /some/xml/file.xml $top_story_xml = new SimpleXMLElement($file_topstory, NULL, TRUE); If the XML doc contains (for example) a URL with an '&' in it then the script fails. I'd like to do something like this: if(is_valid_xml($file_topstory)){ $top_story_xml = new SimpleXMLElement($file_topstory, NULL, TRUE); }else{ // ERROR }
How To Authenticate When Using SimpleXML
I've got an RSS feed I'd like to consume from our Sharepoint server. When I try: $xml = simplexml_load_file($url); I get failed to open stream: HTTP request failed! HTTP/1.1 401 Unauthorized This is understandable as I need to specify a username and password to access the RSS. How can I do this with SimpleXML, or, should I first call the URL with cURL and work with the stream locally? I thought there may be some global params I could set for the stream handling library of PHP.
PHP5 Simplexml
I'm trying to output from an XML string and am having no luck. I'm using PHP5 here. If I print_r the array I get all the results plus extra text, but am unable to extract the individual response. Any pointers appreciated. Here's the code that shows the results... $get_all_value = $xmlrpc_resp->value(); $albums_array = php_xmlrpc_decode($get_all_value); print $albums_array['string']; Here's the result string that I want to break up ... xmlrpcval Object ( [me] => Array ( [string] => <photos page="1" pages="1" perpage="500" total="155"> <photo id="114766115" owner="xxxxxx" secret="xxxxxx" server="50" title="Water Pump, Bushy Park" ispublic="1" isfriend="0" isfamily="0" /> <photo id="114765757" owner="xxxxxx" secret="xxxxxx" server="36" title="Deer, Bushy Park" ispublic="1" isfriend="0" isfamily="0" /></photos> ) [mytype] => 1 [_php_class] => )Many thanks
SimpleXML Question
I'm running in to a little issue with SimpleXML, and wondered if anyone knew if it was normal implementation for SimpleXML, or I'm not using a correct flag, or even it's a an issue that should be resolved. I'm actually only just starting to use SimpleXML with any vigor, so I may well be mistaken about what I think it should do... Basically, if you take this simple chunk of XML:
Merging XML In PHP Using SimpleXML And DOM
I'm having trouble trying to merge two SimpleXML objects (user preference settings) in PHP. It should be simple enough - the objects have the same root element, and I simply want to merge at the top child level. However, the code I'm providing here, while it executes, does not work. At the end of the merge() function, the merged preferences are empty. Code:
Writing To XML Using Either DOM Or SimpleXML
I've been having quite some trouble figuring out specific XML coding in PHP5. I'm trying to edit and remove specific tags in a specific way using DOM (I'd rather use SimpleXML but it seems rather limited on this area). Code:
Parse Xml-rpc Using SimpleXML
I am trying to parse through a XML document...a XML-rpc response to be exact...the good thing is the code is doing as its told. Code:
SimpleXML Catching 404
I'm building a script with the last.fm datafeeds. When a incorrect username is given to the script, the last fm site throws a 404, and results in this PHP error: Warning: simplexml_load_file(http://ws.audioscrobbler.com/1.0/user/RichardJohn/tasteometer.xml?with=) [function.simplexml-load-file]: failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found in /home/richardm/public_html/lastfmcompatibility.php on line 12 Warning: simplexml_load_file() [function.simplexml-load-file]: I/O warning : failed to load external entity "http://ws.audioscrobbler.com/1.0/user/RichardJohn/tasteometer.xml?with=" in /home/richardm/public_html/lastfmcompatibility.php on line 12 There was a problem loading the data feed. Is there a way to catch this error and just present a friendly error?
SimpleXML & Google Images
I'm writing a script that would (hopefully) search google images for whatever, and then return a list of URLs for the image. Right now I have: $dom = new DomDocument(); $url = "http://images.google.com/images?q=hello"; $dom->loadHTMLFile($url); $sxe = simplexml_import_dom($dom); foreach($sxe->xpath('//img') as $node) { echo $node->src; } What this is supposed to do (line by line): Make a new DomDocument Define $url load the HTML file from $url make a simpleXML object from the loaded DOM go through all the image tags (using a DomNodeList w/ xpath) and print out the src attribute of the node.
Simplexml + Namespace +attributes
I have an XML file with some elements like those below <core:District Id="AB01"> <core:Name>NORTH EAST</core:Name> <core:Association Type="type1">VALUE 1a</core:Association> <core:Association Type="type2">VALUE 1b</core:Association> <core:Association Type="type3">VALUE 1c</core:Association> </core:District> <core:District Id="AB02"> <core:Name>NORTH WEST</core:Name> <core:Association Type="type1">VALUE 2a</core:Association> <core:Association Type="type2">VALUE 2b</core:Association> <core:Association Type="type3">VALUE 2c</core:Association> </core:District> I'm trying to parse it using simplexml I have: $districts = $xmlfile->children($core); foreach ($districts as $key => $value) { echo "Name = " . $value->Name . " "; echo "Region1 = " . $value->Association[0] . " "; echo "Region2 = " . $value->Association[1] . " "; echo "Region3 = " . $value->Association[2] . " "; } This works fine, but I am unable to access the Id attribute in the opening District element, i.e. AB01 or AB02. Would anyone be able to suggest how I might get that value with simplexml?
How To Search Xml W/simplexml Using Xpath()
I've been lookin over some simplexml notes/docs and i havent really found a way to search and return results example: <?xml ...?> <products> <cat1> <item> <name>product 1</name> <color>blue</color> </item> </cat1> <cat2> <item> <name>product 2</name> <color>blue</color> </item> </cat2> </products> if the user searches "blue", then i should be able to step through and process the valid <item> structures... same for if they search for "product 1", then just process the one valid structure (including its category)...
Remove Duplicate Items From A Simplexml Object
$foos = simplexml_load_file("bar.xml"); Lets say bar.xml has 50 entries and lets say 25-50% of those are duplicates. How would I get rid of those. Here is how I'm using it foreach($foos as $foo){ echo $foo->entry;} I don't think that $foos or $foos->entry is an array so array_unique won't work.
Problems Using PEAR HTTP_Request In Combination With SimpleXML
I'm just beginning with PHP and I'm trying to figure out how to handle HTTP Requests/Response with web services such as eBay and PayPal. In my research I've come across HTTP_Request included with PEAR. I've gotted it installed and tested successfully with the following: <?php require_once "HTTP/Request.php"; $req =& new HTTP_Request("http://www.ebay.com/"); if (!PEAR::isError($req->sendRequest())) { echo $req->getResponseBody(); } ?> That displays ebay's web site when I load the page so it seems that PEAR is working correctly. I'm trying now to move on and do an actual call to their API. It's the easiest call you can make with their API and it simply returns the official eBay time. Here is what I've got: <?php require_once "HTTP/Request.php";?> <?php $eBayAPICallName = "GeteBayOfficialTime"; $APIURL = "https://api.ebay.com/ws/api.dll"; $DevID = "My_Dev_ID_Here"; $AppID = "My_App_ID_Here"; $Cert = "My_Cert_Here"; $AuthToken = "My_Auth_Token_Here"; //eBay GetOfficialTime request $requestXMLBody = "<?xml version=""1.0"" encoding=""utf-8""?>"; $requestXMLBody .= "<GeteBayOfficialTimeRequest xmlns=""urn:ebay:apis:eBLBaseComponents"">"; $requestXMLBody .= "<RequesterCredentials>"; $requestXMLBody .= "<eBayAuthToken>" . $AuthToken . "</eBayAuthToken>"; $requestXMLBody .= "</RequesterCredentials>"; $requestXMLBody .= "</GeteBayOfficialTimeRequest>"; $req =& new HTTP_Request(); $req -> setURL($APIURL); $req -> setMethod(HTTP_REQUEST_METHOD_POST); $req -> addPostData($requestXMLBody); $req -> addHeader("X-EBAY-API-COMPATIBILITY-LEVEL", "511"); $req -> addHeader("X-EBAY-API-SESSION-CERTIFICATE", $DevID . ";" . $AppID . ";" . $Cert); $req -> addHeader("X-EBAY-API-DEV-NAME", $DevID); $req -> addHeader("X-EBAY-API-APP-NAME", $AppID); $req -> addHeader("X-EBAY-API-CERT-NAME", $Cert); $req -> addHeader("X-EBAY-API-CALL-NAME", $eBayAPICallName); $req -> addHeader("X-EBAY-API-SITEID", "0"); $req -> addHeader("X-EBAY-API-DETAIL-LEVEL", "0"); $XMLResponse = simplexml_load_string($req -> sendRequest()); echo $XMLResponse -> asXML(); ?> The idea behind this (from what i can piece together from tutorials and everything I've been studying) is that it constructs the basic XML string to use and uses PEAR's HTTP_Request to send it off. I'm storing the response in $XMLResponse with the SimpleXML PHP function hoping I could display the XML response in the browser to ensure things are working....but they're not. When I run this page I get a blank white browser back. View source has nothing but the empty basic html tags. All of the headers I've added were taken from working ASP scripts so know those are good (unless I've just done something wrong with syntax there or something). I've tested the simplexml stuff successfully using basic XML files located on my disk so I thought I had that setup correctly too. Obviously something is wrong somewhere, though.
XML File, Character Entities And SimpleXML Parser
I have the following XML file: <?xml version=1.0'?> <!DOCTYPE names [ <!ENTITY eacute "(ampersand)#233;"> ]> <site> <section id='about' name='about'> </section> <section id='portfolio' name='portfolio'> </section> <section id='resume' name='résumé'> </section> </site> I parse it with simpleXML, but by the time "resume" (you know-- the kind with e-acute characters) gets to the browser, the entities get mangled. Note that I *am* using the proper "DOCTYPE names" directive at top of the XML file, and I am saving my files as UTF8. Also note that in the code above, I replaced the ampersand with the word "ampersand" so it wouldn't parse on this message board. I think I'm missing a part of the big picture here. Any ideas?
Special Characters In XML Files Parsed With SimpleXML
I got a problem; when using php4 parsing xml files i get special characters displayed good. When using the simpleXML class, the special characters stay. example: ’ shows as ’ insteeds of ' Does anyone know how to fix this?
SimpleXML And Load Php File (Content-type: Text/xml)
I'm taking my first steps with xml and SimpleXML functions. xml.php (It could be made dynamically with a mysql result I post this snippet for example) PHP Code xml.php: <?php $xmlstr = "<?xml version="1.0" standalone="yes"?>"; $xmlstr .= "<movies> <movie>Behind the Parser</movie> </movies>"; header('Content-type: text/xml; charset=utf-8'); echo $xmlstr; ?> PHP Code loadXml.php: I've got this nasty error : Warning: xml.php:2: parser error : Start tag expected, '<' not found in c:xxxwwwxmlexamplemioplot.php on line 3 Warning: $xmlstr = ""; in c:xxxwwwxmlexampleloadXml.php on line 3 Warning: ^ in c:xxxwwwxmlexampleloadXml.php on line 3 bool(false) I've got the same error in my web site . xml.php is a valid xml file, isn't it ? Therefore I'm wondering why the snippet doesn't work ?
Warning: Simplexml_load_file() [function.simplexml-load-file]:
heres the errors: Warning: simplexml_load_file() [function.simplexml-load-file]: core/combat/magic/Spark.const.xml:4: parser error : Extra content at the end of the document in C:Program Filesxampphtdocswinterswordcorecombatcombat.class.php on line 481 Warning: simplexml_load_file() [function.simplexml-load-file]: <mastery>Death</mastery> in C:Program Filesxampphtdocswinterswordcorecombatcombat.class.php on line 481 Warning: simplexml_load_file() [function.simplexml-load-file]: ^ in C:Program Filesxampphtdocswinterswordcorecombatcombat.class.php on line 481 and heres the .xml document: Code:
[SimpleXML] Assigning Values To Elements Found With XPath
I want to find all elements named "field" in an XML doc and assign a new value to each one. I'd tried something like this: foreach ($xml->xpath('//field') as &$field) $field = $value; But that doesn't work, because (I think) XPath returns a temporary array, not a reference to an actual element. ("PHP Fatal error: Cannot create references to elements of a temporary array expression") Is there a way to assign values to elements located with XPath, or do I just have to iterate over the whole document?
Parsing .inc As .php
how do I parse .inc as .php files? Is it that useful to do this? Is it so unsafe to include() them otherwise? On my Linux box, I've got both httpd and httpd2.conf (don't ask me, it was auto-configured that way). I think both files are useful, but in which of these do I insert whatever you're going to give me?
URL Parsing.
I have come up with a couple ideas, but I would like some input on the most effective way to parse a URL from the body of a mail message. I have a small script which accesses mail for an account and retrieves the message body(imap_body). I want to parse through the body and pull out URL's, anyone have some good advice on a practicle method?
Parsing XML,RSS Through PHP
Do anybody know 'bout parsing RSS through XML (PHP). I wanna learn RSS, but before that i must know XML. It would be helpful if anybody guide me in the right direction from where to take start learning XML (link, url). And after having the elementary knowledge 'bout XML i would be able to parse RSS.
Parsing XML
I'm trying to figure out how to parse very simple XML files using PHP 4.3. I have been unsuccessful at finding simple explanations of how to do this. I found the following code somewhere (can't remember where) and it works great EXCEPT it does not keep my CSS class tags. The result is that everything shows up as a <p> rather than <p class="text">, etc. How do I modify this code to allow this? Or is there a better way to accomplish this? <?php $file = "myfile.xml"; $map_array = array( "bold" => "b", "emphasis" => "i", "literal" => "tt" ); function startElement($parser, $name, $attrs) { global $map_array; if (isset($map_array[$name])) { echo "<$map_array[$name]>"; } } function endElement($parser, $name) { global $map_array; if (isset($map_array[$name])) { echo "</$map_array[$name]>"; } } function characterData($parser, $data) { echo $data; } $xml_parser = xml_parser_create(); // use case-folding so we are sure to find the tag in $map_array xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, true); xml_set_element_handler($xml_parser, "startElement", "endElement"); xml_set_character_data_handler($xml_parser, "characterData"); if (!($fp = fopen($file, "r"))) { die("could not open XML input"); } while ($data = fread($fp, 4096)) { if (!xml_parse($xml_parser, $data, feof($fp))) { die(sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser))); } } xml_parser_free($xml_parser); ?>
Parsing An URL
I want a PHP script that will for example split http://example.com/dir/index.htm into http://example.com/dir and index.htm It also needs to split up an URL with GET variables at the end. eg http://example.com/dir/link.php?id=123&no=abc Any help would be appreciated...
Parsing XML
I have some problems with parsing this sample xml file. <section id="L11"> <group id="L21"> <field key="name1" value="1"/> <field key="name2" value="2"/> <field key="name3" value="3"/> <field key="name4" value="4"/> <field key="name5" value="5"/> <field key="name6" value="6"/> </group> <group id="L22"> <field key="name7" value="7"/> <field key="name8" value="8"/> <field key="nam9" value="9"/> </group> </section> <section id="L12"> <group id="L23"> <field key="name10" value="10"/> <field key="name11" value="11"/> </group> <group id="L24"> <field key="name12" value="12"/> <field key="name13" value="13"/> <field key="nam14" value="14"/> </group> </section> PHP Code:
Xml Parsing With Php
I use PHP (and PHP socket functions) to exchange very short XML documents between two Flash clients like this: <MESSAGE id="myid" text="mytext" /> I don't parse the XML document within PHP but send back the XML document made by the Flash client to another Flash client with a php socket and Flash parse it with its own XML parser ... In order to detect errors or non-XML data I do like this (in php): switch (true){ case ( ereg("<", trim($XMLdata)) ): print 'xmldata' break; default: print 'no xmldata' } (I must do this because Flash sends an empty "heartbeat" every 5 seconds, which is not XML data) Now, I need to interpret my XML document inside php cause I want to make php execute some commands when it receives a certain type of XML element. XML data that can be sent from Flash : <MESSAGE id="myid" text="mytext" /> or <COMMAND1 /> or <COMMAND2 /> or or an empty string "" . (in php) I can do : switch (true){ case ( ereg("<MESSAGE", trim($XMLdata)) ): print 'xmldata is a txt message' break; case ( ereg("<COMMAND1", trim($XMLdata)) ): print 'xmldata is a command1' break; case ( ereg("<COMMAND2", trim($XMLdata)) ): print 'xmldata is a command2' break; default: print 'no xmldata' } But what I'm wondering is whether it is the good way to proceed, wouldn't it be faster to parse the xml document within php with Expat library included when it receives a document "<COMMAND idcom="1" />" and interpret "idcom" value instead of doing an "ereg("<COMMAND1", trim($XMLdata))?
XML Parsing!
I've looked and searched and tried to find information about how to solbve this problem, but I can't. I'm beginning to think that I should start from scratch to do it right. I am trying to parse the data from the weather channel in PHP. A slice of the data looks like this: <weather ver="2.0"> <cc> <lsup>3/4/05 8:50 AM Local Time</lsup> <obst>Vasteras, Sweden</obst> <tmp>-7</tmp> <flik>-12</flik> <t>Mostly Cloudy</t> <icon>28</icon> <bar> <r>1,010.8</r> <d>steady</d> </bar> <wind> <s>10</s> <gust>N/A</gust> <d>180</d> <t>S</t> </wind> <hmid>83</hmid> <vis>10.0</vis> <uv> <i>0</i> <t>Low</t> </uv> <dewp>-9</dewp> <moon> <icon>22</icon> <t>Waning Half, Last Quarter</t> </moon> </cc> </weather>.......
Looking For Help With RSS Parsing
I'm working on a script to work with podcast feeds (RSS) and have found the lasRSS parser to be quite good. http://lastrss.webdot.cz/ I've modified this to work with i-tunes tags (as they have added their own to the RSS vocabulary!) however I still have one set of tags - category - that I am stuck with. an example of these tags (Category Technology, Sub Category Computers) would be: <ITUNES:CATEGORY TEXT="Technology"> <ITUNES:CATEGORY TEXT="Computers"></ITUNES:CATEGORY> </ITUNES:CATEGORY>
Parsing XML?
I have a slight problem with parsing XML: If the tag was say - <Something ID="12"> - My parser is only retrieving the 'Something' part, and discarding the 'ID="12"'. Code: function startElement($xml_parser, $name, $attrs) { echo $name; //this is the part with the issue } function endElementStuff($xml_parser, $name) { } function charData($xml_parser, $data) { echo $data; } $xml_parser = xml_parser_create(); $ml_set_element_handler($xml_parser, "startElement", "endElementStuff"); xml_set_character_data_handler($xml_parser, "charData"); xml_parse($xml_parser, $result, TRUE); xml_parser_free($xml_parser);
Parsing Xml
I am trying to parse a very large rdf file, 585 MB to be exact. It's content.rdf.u8, dump file from the open source directory: www.dmoz.com/rdf I have parse the smaller version (30K) of the file, but no luck with big one. If anyone has parsed this file or knows how to parse this type of file.
Xml Parsing
i am trying to read an xml file using php and i am stuck at a place, below are my xml tags, i have to retrieve the attributes of the parent and the corresponding tags Code:
Xml Parsing
I've spent many hours trying to understand why the dom-functions in php do this and that, but the following I can't understand: My xml-file looks like: <Data> <Article> <Number>3746</Number> <Description>This is the article description</Description> <Groups> <Group1>Group1</Group1> <Group2>Group2</Group2> <Group3>Group3</Group3> </Groups> </Article> </Data> having the current node "Groups", I call //-- snip $childNodes = $curNode->child_nodes(); echo "Number of child-nodes: " . count($childNodes) . "<br>"; //-- /snip The output is: "Number of child-nodes: 7" When I echo the node_name() of each child-node, every second node is called #text Could anyone of you explain why php reacts like this? I would expect a child-count of three and definitely no #text-nodes...
RDF Parsing
I'm looking for an easy to use and understand RDF parser for PHP. Preferably lightweight if possible. I'm currently trying to get my head around this one.: http://www.wiwiss.fu-berlin.de/suhl/bizer/rdfapi/ are there any others that might be considered to be better quality or easier to use?
Parsing An XML (same TAG Name)
I am stuck processing an XML file. The problem I am having, is I have the same TAG name - Url - at the same depth, so the value from the last Url read in is what get saved. I have tried every option I can think of to put each URL tag into its own variable, without any luck. I removed portions of the code that does not affect the outcome (for a smaller post). Here's a snippet of the XML, and when the code (below) runs, no matter what, the value of $items[$itemcount]['url'] is always /TiVoVideoDetails?id=465887. - <CustomIcon> <Url>urn:tivo:image:save-until-i-delete-recording</Url> <ContentType>image/*</ContentType> <AcceptsParams>No</AcceptsParams> </CustomIcon> - <TiVoVideoDetails> <Url>/TiVoVideoDetails?id=465887</Url> <ContentType>text/xml</ContentType> <AcceptsParams>No</AcceptsParams> </TiVoVideoDetails> PHP code: <?php class Tivo_XML { var $dvr; function parseTiVoXML() { global $items; $this->parser = xml_parser_create(); xml_set_object($this->parser, &$this); xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, false); xml_set_element_handler($this->parser, "_tivostart_element", "_tivoend_element"); xml_set_character_data_handler($this->parser, "_tivodata"); $file = $this->dvr . "_nowplaying.xml"; $tivoxmlstr = file_get_contents ($file); $tivoxmlstr = str_replace("&", "%amp;%", $tivoxmlstr); xml_parse($this->parser, $tivoxmlstr , true) or die (sprintf("XML Error: %s at line %d", xml_error_string(xml_get_error_code($this->parser)), xml_get_current_line_number($this->parser))); xml_parser_free($this->parser); return $items; }
|