473,396 Members | 2,129 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to parse XML with SimpleXML

I have pass a URL statement to a server:

Expand|Select|Wrap|Line Numbers
  1. http://query.directrdr.com/ptrack?pid=458&v_url=http%3A%2F%2Fwww.google.com&feed=1&said=321&ip=96.226.232.199&ua=Mozilla%2F4.0+%28compatible%3B+MSIE+7.0%3B+Windows+NT+5.1%3B+.NET+CLR+2.0.50727%3B+.NET+CLR+3.0.4506.2152%3B+.NET&keyword=
The server processes that and returns an XML file like so:

Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="utf-8" ?> 
  2. - <ads Type="Popup">
  3. - <ad>
  4. - <url>
  5. - <![CDATA[ 
  6. http://www.directrdr.com/v3.php?pid=458&cid=0&crid=0&t=0(0)&cc=840&said=321&params=192517761ab0192da0b22aa71dd64470e1c7545a-3U.ssU.sFs.w33%09f.ffsfff%09jotLsoqaIEvERY%09ws4kU4UwFw%092vvR%3A%2F%2FwwFsFsWai.ERvzv.EtQ%2FERY.1NR%3FR%3DwwFsFs%26RjavLIamqL%3Df.ffw%26atLmqL%3Df.ffw%26Wai%3D2vvR%25Fh%25s6%25s6nnn.zttziI.EtQ%26qR%3D3U.ssU.sFs.w33%26jqo%3DkSu%26NWAqo%3DkSu-Fsw%26NIiIEvIodI0ntao%3DzttziI%20EtQ%26NIiIEvIoVqNvqLzgo%3D4S3fF4w&pc=19-7590371&vurl=http%3A%2F%2Fwww.google.com&mm=20
  7.   ]]> 
  8.   </url>
  9.   <cpvrate>0.002</cpvrate> 
  10.   <creativeid>0384258679</creativeid> 
  11.   <campaignid>19-7590371</campaignid> 
  12.   <max-imp-per-user>1</max-imp-per-user> 
  13.   <frequency-period>24</frequency-period> 
  14.   </ad>
  15.   </ads>

I attempt to capture portions of the XML data by using SimpleXML:

Expand|Select|Wrap|Line Numbers
  1. simplexml_load_file($request_url,'SimpleXMLElement', LIBXML_NOCDATA);
  2. $adtype = (string) $xml['Type'];
  3. $outurl = (string) $xml->ad->url;
$outurl is now set to:

Expand|Select|Wrap|Line Numbers
  1. http://www.directrdr.com/v3.php?pid=458&cid=0&crid=0&t=0(0)&cc=840&said=321¶ms=f187e570d6b79abd9b963fbde6d108c7c8174f5d-3U.ssU.sFs.w33%09f.ffsfff%09jotLsoqaIEvERY%09ws4kU4uwu3%092vvR%3A%2F%2FwwFsFsWai.ERvzv.EtQ%2FERY.1NR%3FR%3DwwFsFs%26RjavLIamqL%3Df.ffw%26atLmqL%3Df.ffw%26Wai%3D2vvR%25Fh%25s6%25s6nnn.zttziI.EtQ%26qR%3D3U.ssU.sFs.w33%26jqo%3DkSu%26NWAqo%3DkSu-Fsw%26NIiIEvIodI0ntao%3DzttziI%20EtQ%26NIiIEvIoVqNvqLzgo%3D4S3fF4w&pc=19-7590371&vurl=http%3A%2F%2Fwww.google.com&mm=22
As you can see, there is a carriage return character within the $outurl variable (=321¶ms=), which shouldn't be there. Any ideas why that is happening? Also, are parentheses allowed in an url, such as "(0)" above.
May 24 '10 #1
1 1937
Never mind. My developer figured it out.

&para = ¶
in ascii

&params is getting converted into ¶ms

Now off to find a workaround.
May 24 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: wenke | last post by:
Hi, I am using the following code (see below) from php.net (http://www.php.net/manual/en/ref.xml.php, example 1) to parse an XML file (encoded in UTF-8). I changed the code slightly so that the...
6
by: * | last post by:
I need to devise a way of reading the following XML data and taking the Job_ID and putting into a database using the access_code and the adt_company_id. any idea of how I might be able to do...
5
by: Mike McGavin | last post by:
Hi everyone. I've been trying for several hours now to get minidom to parse namespaces properly from my stream of XML, so that I can use DOM methods such as getElementsByTagNameNS(). For some...
6
by: Ulrich Vollenbruch | last post by:
Hi all! since I'am used to work with matlab for a long time and now have to work with c/c++, I have again some problems with the usage of strings, pointers and arrays. So please excuse my basic...
0
by: Uncle Leo | last post by:
I created an OleDbDataAdapter with the wizard in Visual Studio 2003. It created a dataset, connectionstring etc. for me to work with. It also created a .xsd file where one of the columns type is...
5
by: barronmo | last post by:
I'm having difficulty getting the following code to work. All I want to do is remove the '0:00:00' from the end of each line. Here is part of the original file: 3,3,"Dyspepsia NOS",9/12/2003...
2
by: Zvi | last post by:
Hi All, Can someone tell me why id the following not working? I have a soap response envelope, for test purpose it's just a string and I create ElementTree from it. Then I try to find Response...
0
by: gnewsgroup | last post by:
I need to bind *some* nodes of an xml document to an asp.net Menu control. The problem is that the XML document uses the same node name and attribute name for for the entire document among all...
12
by: pindoriya1 | last post by:
Hi, m using split function to parse the csv file ..... i m getting problem in one line of file which looks like this : "BLUEUSBXM","X-MICRO (XBT-DG5R (C) R1) BLUETOOTH USB DONGLE PLUS, CLASS...
2
by: ashmir.d | last post by:
Hi, I am trying to parse an xml file using the minidom parser. <code> from xml.dom import minidom xmlfilename = "sample.xml" xmldoc = minidom.parse(xmlfilename) </code> The parser is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.