0

Currently I have a PHP file that reads posted XML and then converts/outputs it to JSON. This file looks like this:

<?php 

file_put_contents('myxmlfile.xml', file_get_contents('php://input'));
$xmldoc = new DOMDocument();
$xmldoc->load("myxmlfile.xml");
$xpathvar = new DOMXPath($xmldoc);

// Etc etc, for the purpose of my question seeing the rest isn't necessary
// After finishing the conversion I save the file as a JSON file.

file_put_contents('myjsonfile.json', $JSONContent);

?>

The data I'm receiving comes in XML format. To convert it I'm currently saving it as an XML file, and then immediately after creating a new DOMDocument() and loading it in. My question is, is there any way I can cut out the middle man and just load in the XML directly using file_get_contents()?

Ideally it would be this (didn't work):

$xmldoc->load(file_get_contents("php://input"));

If anyone could help me do this I'd really appreciate it!

Thanks

0

1 Answer 1

1

To load from string, instead of filename, use loadXML method.

$xmldoc->loadXML(file_get_contents("php://input"));
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.