how do i post an xml string in php

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • anubhavjha
    New Member
    • Jul 2008
    • 22

    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
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #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.

    Comment

    • anubhavjha
      New Member
      • Jul 2008
      • 22

      #3
      Originally posted by pbmods
      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

      Comment

      • pbmods
        Recognized Expert Expert
        • Apr 2007
        • 5821

        #4
        On the form page:
        [code=php]
        session_start() ;
        $_SESSION['xml'] = '<xml data />';
        [/code]

        On the processing page:
        [code=php]
        session_start() ;
        $xml = $_SESSION['xml'];
        [/code]

        Alternatively, you might want to do this, instead:
        [code=php]
        $xml = htmlentities('< xml data />', ENT_COMPAT);

        ?>
        <input ... value="<?php echo $xml; ?>" />
        [/code]

        Comment

        • anubhavjha
          New Member
          • Jul 2008
          • 22

          #5
          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,,

          Comment

          • pbmods
            Recognized Expert Expert
            • Apr 2007
            • 5821

            #6
            Show me the code you're using. It sounds like the XML is not getting properly escaped.

            Comment

            • anubhavjha
              New Member
              • Jul 2008
              • 22

              #7
              [code=html]<input type="hidden" name="ticketxml " id="ticketxml" value= "
              &lt?xml version=\'1.0\' encoding=\'UTF-8\'?&gt;
              &lt;ticket&g t;
              &lt;user&gt;
              &lt;title&gt;Mr .&lt;/title&gt;
              &lt;firstname&g t;Chris.&lt;/firstname&gt;
              &lt;lastname&gt ;Elliott&lt;/lastname&gt;
              &lt;email&gt;ch ris_elliott@sym antec.com&lt;/email&gt;
              &lt;phone&gt;11 11111111&lt;/phone&gt;
              &lt;username&gt ;~Mr. Chris Elliott &lt;/username&gt;
              &lt;shortdesc&g t;foo&lt;/shortdesc&gt;
              &lt;problemtype &gt;order_billi ng&lt;/problemtype&gt;
              &lt;zip&gt;& lt;/zip&gt;
              &lt;/user&gt;
              &lt;systeminfo& gt;
              &lt;name&gt;Win dows XP 5.1&lt;/name&gt;
              &lt;operatingsy stem&gt;
              &lt;name&gt;Win dows XP 5.1&lt;/name&gt;
              &lt;localtime&g t;7/8/2008 3:12:49 PM GMT: 0&lt;/localtime&gt;
              &lt;symanteccor elc&gt;Startup Type: State: Status:&lt;/symanteccorelc& gt;
              &lt;/operatingsystem &gt;
              &lt;browser& gt;
              &lt;name&gt;Int ernet Explorer&lt;/name&gt;
              &lt;version&gt; 6.0.2900.2180&l t;/version&gt;
              &lt;/browser&gt;
              &lt;memory&g t;
              &lt;total&gt;To tal: 3070MB Load: 54 percent&lt;/total&gt;
              &lt;available&g t;46 percent&lt;/available&gt;
              &lt;/memory&gt;
              &lt;diskspace&g t;
              &lt;total&gt;93 .1 GB&lt;/total&gt;
              &lt;available&g t;3.32 GB&lt;/available&gt;
              &lt;/diskspace&gt;
              &lt;conntype&gt ;lan&lt;/conntype&gt;
              &lt;cpu&gt;2 394 Mhz&lt;/cpu&gt;
              &lt;opticaldriv es&gt;CD-ROM Drive [D:] Standard CD-ROM drives&lt;/opticaldrives&g t;
              &lt;/systeminfo&gt;
              &lt;products&gt ;
              &lt;product& gt;

              &lt;curdefs&gt; 20080708.003&lt ;/curdefs&gt;
              &lt;name&gt; Norton AntiVirus&lt;/name&gt;
              &lt;version& gt; 2008&lt;/version&gt;
              &lt;language&gt ; English &lt;/language&gt;
              &lt;licensetype &gt; Standard &lt;/licensetype&gt;
              &lt;symskucurre nt&gt;&lt;/symskucurrent&g t;
              &lt;symskufamil y&gt;&lt;/symskufamily&gt ;
              &lt;symskumedia &gt;&lt;/symskumedia&gt;
              &lt;partnername &gt;&lt;/partnername&gt;
              &lt;activation& gt;
              &lt;status&gt;& lt;/status&gt;
              &lt;prodactkey& gt;&lt;/prodactkey&gt;
              &lt;/activation&gt;
              &lt;subscriptio n&gt;
              &lt;status&gt;& lt;/status&gt;
              &lt;serialnum&g t;&lt;/serialnum&gt;
              &lt;/subscription&gt ;

              &lt;/product&gt;
              &lt;/products&gt;
              &lt;ocssession& gt;
              &lt;contact& gt;
              &lt;method&gt;c ontactEmail&lt;/method&gt;
              &lt;filter&gt;o rder_billing&lt ;/filter&gt;
              &lt;/contact&gt;
              &lt;/ocssession&gt;
              &lt;/ticket&gt; ">[/code]

              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
              Last edited by pbmods; Aug 5 '08, 09:58 PM. Reason: Added CODE tags.

              Comment

              • pbmods
                Recognized Expert Expert
                • Apr 2007
                • 5821

                #8
                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:

                [code=php]
                $xml = str_replace(arr ay("\r", "\n", "\t", ' '), '', $xml);
                [/code]

                Comment

                Working...