Create a SimpleXMLElement Object using xml from form

capture xml code from html form and use in php script to creata Simple

Page 1 of 1

3 Replies - 8304 Views - Last Post: 25 March 2009 - 05:15 PM Rate Topic: -----

#1 adamido  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 30-October 08

Create a SimpleXMLElement Object using xml from form

Posted 25 March 2009 - 10:21 AM

Hi there,

I am trying to create a simpleXMLElement Object. The way I am doin this is by first creating a form as so:


<form action="simpleXMLElementObject.php" method="post" >

Enter your XML code here:

<br/><textarea rows="25" cols="40" name="code"></textarea>
<br/><input type="submit" name="mode" value="create image"/>

</form>




..which works fine. then when the create image button is clicked an SVG image is meant to be created. however, before i move onto creating the SVG image i first need to convert the xml data submitted in the form, into a SXMLElement object. here is what i have:


<?php


$xmlstring = $_POST["code"];

echo ($xmlstring);

$xml = new SimpleXMLElement($xmlstring);

var_dump($xml);
  
?>




so basically i try to capture the xml coding from the form and then I i submit this to the php script which should create the SXMLE object. i create a string from the xml data, then create the object and then show this but it doesnt work. when i enter some test data such as this into the form and the click the button:


<?xml version="1.0"?>
<dataSet>
<point><x>25</x><y>25</y></point>
<point><x>35</x><y>35</y></point>
<point><x>55</x><y>25</y></point>
<point><x>55</x><y>55</y></point>
</dataSet>




i get the following error message:


Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /mnt/moya/home/ugrad/ma701ab/public_html/simpleXMLElementObject.php:8 Stack trace: #0 /mnt/moya/home/ugrad/ma701ab/public_html/simpleXMLElementObject.php(8): SimpleXMLElement->__construct('') #1 {main} thrown in /mnt/moya/home/ugrad/ma701ab/public_html/simpleXMLElementObject.php on line 8

any help would be much apprecaited. im not asking for coding...if i can just be pushed in the right direction then i can take it from there...i just need some help knowing where im going wrong.

thanks

Is This A Good Question/Topic? 0
  • +

Replies To: Create a SimpleXMLElement Object using xml from form

#2 adamido  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 30-October 08

Re: Create a SimpleXMLElement Object using xml from form

Post icon  Posted 25 March 2009 - 10:55 AM

Hi there,

I am trying to create a simpleXMLElement Object. The way I am doin this is by first creating a form as so:



<form action="simpleXMLElementObject.php" method="post" >

Enter your XML code here:

<br/><textarea rows="25" cols="40" name="code"></textarea>
<br/><input type="submit" name="mode" value="create image"/>

</form>




..which works fine. then when the create image button is clicked an SVG image is meant to be created. however, before i move onto creating the SVG image i first need to convert the xml data submitted in the form, into a SXMLElement object. here is what i have:



<?php


$xmlstring = $_POST["code"];

echo ($xmlstring);

$xml = new SimpleXMLElement($xmlstring);

var_dump($xml);
 
?>




so basically i try to capture the xml coding from the form and then I i submit this to the php script which should create the SXMLE object. i create a string from the xml data, then create the object and then show this but it doesnt work. when i enter some test data such as this into the form and the click the button:



<?xml version="1.0"?>
<dataSet>
<point><x>25</x><y>25</y></point>
<point><x>35</x><y>35</y></point>
<point><x>55</x><y>25</y></point>
<point><x>55</x><y>55</y></point>
</dataSet>




i get the following error message:


Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /mnt/moya/home/ugrad/ma701ab/public_html/simpleXMLElementObject.php:8 Stack trace: #0 /mnt/moya/home/ugrad/ma701ab/public_html/simpleXMLElementObject.php(8): SimpleXMLElement->__construct('') #1 {main} thrown in /mnt/moya/home/ugrad/ma701ab/public_html/simpleXMLElementObject.php on line 8

any help would be much apprecaited. im not asking for coding...if i can just be pushed in the right direction then i can take it from there...i just need some help knowing where im going wrong. what is wrong with LINE 8 as my errors message states!!

thanks
Was This Post Helpful? 0
  • +
  • -

#3 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6066
  • View blog
  • Posts: 23,526
  • Joined: 23-August 08

Re: Create a SimpleXMLElement Object using xml from form

Posted 25 March 2009 - 11:14 AM

Make sure the data you're passing is what you think it is before giving it to SimpleXML. It may have been escaped or encoded.
Was This Post Helpful? 0
  • +
  • -

#4 Valek  Icon User is offline

  • The Real Skynet
  • member icon

Reputation: 542
  • View blog
  • Posts: 1,713
  • Joined: 08-November 08

Re: Create a SimpleXMLElement Object using xml from form

Posted 25 March 2009 - 05:15 PM

Works fine for me. Have you tried escaping the quotes in the XML after it's submitted?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1