0

The situation is as follows. I have to send a defined XML to an url http:\\www.example.com:1234 with some variables that I have to previously define.

XML is like this:

<Title1>
<Title2>Some Text</Title2>
<Title3>Variable 1</Title3>
<Title4>Some Text</Title4>
<Title5>
    <Title51>Variable 2</Title51>
</Title5>
</Title1>

But, I want to define those variables (1, 2) within an html/php form and get method, so the user can introduce both variables and then click on the submit button from the form to send the XML to the previously URL.

Also, XML should have the "Content-Type","application/x-www-form-urlencoded" header.

Is this possible? I've tried to pass these variables directly to the XML and the best that I've come to is to showing the XML and not parsing the php strings.

Also, I've tried some scripts like simplexml from PHP classes, but with no luck so far.

2
  • Are you trying to modify the existing xml file (or creating new file) with new values of <Title3></Title3> and <Title51></Title51> obtained from php $_GET[] ?? Commented Jul 26, 2012 at 11:31
  • @Makesh - I'm trying to modify an existing xml file, if it's possible to pass those values through itself. Otherwise, i won't complain if it's possible to create a fresh new xml with those values pre-loaded. Commented Jul 30, 2012 at 11:57

1 Answer 1

0

1) To modify existing XML with new values . Try this

sample.xml :

<Title1>
   <Title2>Some Text</Title2>
   <Title3>Variable 1</Title3>
   <Title4>Some Text</Title4>
   <Title5>
      <Title51>Variable 2</Title51>
   </Title5>
</Title1>

PHP :

$xml = simplexml_load_file("sample.xml");
$xml->Title3 = $_GET['t3'];              // Updating <Title3></Title3> from GET method
$xml->Title5[0]->Title51 = $_GET['t5'];  // Updating <Title51></Title51> from GET method
$xml->asXML('sample.xml');               // saving the xml file

2)To create new XML file (sample.xml) :

PHP:

$xml = new SimpleXMLElement("<Title1></Title1>");
$xml->Title2='Some Text';
$xml->Title3 = $_GET['t3'];
$xml->Title4='Some Text';
$xml->Title5[0]->Title51 = $_GET['t5'];
$xml->asXML('sample.xml');               // saving the xml file

I have showed you both possibilities mentioned in the comment . Use anyone which comforts you :)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.