471,107 Members | 1,841 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

how do i post an xml string in php

hi friends,

i want to pass an xml string as a hidden field on the php page. How do i do it.

I tried to put the input type as hidden and value as the <xml tag\>. on the target page it does not take any data.

Regards,
Anubhav
Aug 2 '08 #1
7 2023
pbmods
5,821 Expert 4TB
Heya, Anubhav.

You might want to store it as a session variable instead.

If you can't use sessions, make sure you're running your XML through htmlentities() before you output it.
Aug 2 '08 #2
Heya, Anubhav.

You might want to store it as a session variable instead.

If you can't use sessions, make sure you're running your XML through htmlentities() before you output it.
Hi i tried to do this but when i take the post data on the target page i only get the xml data i do not get the xml tags. an example would help on this.

Regs,

Anubhv
Aug 4 '08 #3
pbmods
5,821 Expert 4TB
On the form page:
Expand|Select|Wrap|Line Numbers
  1. session_start();
  2. $_SESSION['xml'] = '<xml data />';
  3.  
On the processing page:
Expand|Select|Wrap|Line Numbers
  1. session_start();
  2. $xml = $_SESSION['xml'];
  3.  
Alternatively, you might want to do this, instead:
Expand|Select|Wrap|Line Numbers
  1. $xml = htmlentities('<xml data />', ENT_COMPAT);
  2.  
  3. ?>
  4. <input ... value="<?php echo $xml; ?>" />
  5.  
Aug 4 '08 #4
Hi thanks for the help i tried doing this

but it was removing the xml tags when the response was send to the processing page.

<name> rabert </name> was shown as only rabert
then i used escape characters
&lt;name&gt; rabert &lt;/name&gt; and it worked
but it does not take the following

&lt;member count=22&gt; permanent &lt;/member&gt;

Any Ideas,,
Aug 5 '08 #5
pbmods
5,821 Expert 4TB
Show me the code you're using. It sounds like the XML is not getting properly escaped.
Aug 5 '08 #6
Expand|Select|Wrap|Line Numbers
  1. <input type="hidden" name="ticketxml" id="ticketxml" value= "
  2.             &lt?xml version=\'1.0\' encoding=\'UTF-8\'?&gt;
  3.             &lt;ticket&gt;
  4.              &lt;user&gt;
  5.                 &lt;title&gt;Mr.&lt;/title&gt;
  6.                 &lt;firstname&gt;Chris.&lt;/firstname&gt;
  7.                 &lt;lastname&gt;Elliott&lt;/lastname&gt;
  8.                 &lt;email&gt;chris_elliott@symantec.com&lt;/email&gt;
  9.             &lt;phone&gt;1111111111&lt;/phone&gt;
  10.             &lt;username&gt;~Mr. Chris Elliott &lt;/username&gt;
  11.         &lt;shortdesc&gt;foo&lt;/shortdesc&gt;
  12.         &lt;problemtype&gt;order_billing&lt;/problemtype&gt;
  13.         &lt;zip&gt;&lt;/zip&gt;
  14.         &lt;/user&gt;
  15.             &lt;systeminfo&gt;
  16.             &lt;name&gt;Windows XP 5.1&lt;/name&gt;
  17.         &lt;operatingsystem&gt;
  18.             &lt;name&gt;Windows XP 5.1&lt;/name&gt;
  19.             &lt;localtime&gt;7/8/2008 3:12:49 PM GMT: 0&lt;/localtime&gt;
  20.             &lt;symanteccorelc&gt;Startup Type:  State:  Status:&lt;/symanteccorelc&gt;
  21.         &lt;/operatingsystem&gt;
  22.         &lt;browser&gt;
  23.             &lt;name&gt;Internet Explorer&lt;/name&gt;
  24.             &lt;version&gt;6.0.2900.2180&lt;/version&gt;
  25.         &lt;/browser&gt;
  26.         &lt;memory&gt;
  27.             &lt;total&gt;Total: 3070MB Load: 54 percent&lt;/total&gt;
  28.             &lt;available&gt;46 percent&lt;/available&gt;
  29.         &lt;/memory&gt;
  30.         &lt;diskspace&gt;
  31.             &lt;total&gt;93.1 GB&lt;/total&gt;
  32.             &lt;available&gt;3.32 GB&lt;/available&gt;
  33.         &lt;/diskspace&gt;
  34.         &lt;conntype&gt;lan&lt;/conntype&gt;
  35.         &lt;cpu&gt;2394 Mhz&lt;/cpu&gt;
  36.         &lt;opticaldrives&gt;CD-ROM Drive [D:]  Standard CD-ROM drives&lt;/opticaldrives&gt;
  37.     &lt;/systeminfo&gt; 
  38.     &lt;products&gt;
  39.         &lt;product&gt;
  40.  
  41.             &lt;curdefs&gt;20080708.003&lt;/curdefs&gt;
  42.             &lt;name&gt; Norton AntiVirus&lt;/name&gt;
  43.             &lt;version&gt; 2008&lt;/version&gt;
  44.             &lt;language&gt; English &lt;/language&gt;
  45.             &lt;licensetype&gt; Standard &lt;/licensetype&gt;
  46.             &lt;symskucurrent&gt;&lt;/symskucurrent&gt;
  47.             &lt;symskufamily&gt;&lt;/symskufamily&gt;
  48.             &lt;symskumedia&gt;&lt;/symskumedia&gt;
  49.             &lt;partnername&gt;&lt;/partnername&gt;
  50.             &lt;activation&gt; 
  51.                 &lt;status&gt;&lt;/status&gt;
  52.                 &lt;prodactkey&gt;&lt;/prodactkey&gt;
  53.             &lt;/activation&gt;
  54.             &lt;subscription&gt;
  55.                 &lt;status&gt;&lt;/status&gt;
  56.                 &lt;serialnum&gt;&lt;/serialnum&gt;
  57.             &lt;/subscription&gt;
  58.  
  59.         &lt;/product&gt;
  60.     &lt;/products&gt; 
  61.     &lt;ocssession&gt;
  62.         &lt;contact&gt;
  63.             &lt;method&gt;contactEmail&lt;/method&gt;
  64.             &lt;filter&gt;order_billing&lt;/filter&gt;
  65.         &lt;/contact&gt;
  66.     &lt;/ocssession&gt;
  67.     &lt;/ticket&gt; ">
This is the code i am using

what are the other methods can i parse this xml string apart from using the simplexml load string method.

Regards,
Anubhav
Aug 5 '08 #7
pbmods
5,821 Expert 4TB
I see from the source of your post that you are correctly-escaping the XML, so that's not an issue.

Given the size of the string, I'd strongly recommend saving the XML as a session variable.

But if you absolutely have to pass it through the form, strip out all the newlines (and probably whitespace as well just for good measure). Something along the lines of:

Expand|Select|Wrap|Line Numbers
  1. $xml = str_replace(array("\r", "\n", "\t", ' '), '', $xml);
  2.  
Aug 5 '08 #8

Post your reply

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

Similar topics

4 posts views Thread by James Johnson | last post: by
6 posts views Thread by someone | last post: by
reply views Thread by WIWA | last post: by
1 post views Thread by arfeengodil | last post: by
7 posts views Thread by php_mysql_beginer911 | last post: by

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.