Error when trying to parse xml using laravel












0














I am trying to parse the following xml and keep on running into the same error message "Unable to parse XML from string", please see the below error message.



protected function resolveXmlObject($xml): Document
{
if (! $xml) {
throw new InvalidContentException('Unable to parse XML from string.');
}

return $this->document->setContent($xml);
}


I am new to using xml and am unsure what the issue is with the code that I have provided. If someone could point me in the right direction as to what I am doing wrong that would be greatly appreciated.




Controller




use OrchestraParserXmlFacade as XmlParser;

public function upload()
{
$xml = XmlParser::load(asset('xml/data.xml'));

$user = $xml->parse([
'id' => ['uses' => 'programme::id'],
'name' => ['uses' => 'programme.name'],
]);

return view ('projects.upload', compact('user'));
}



XML




<?xml version="1.0" encoding=”UTF-8”?>

<programme data>
<title>Programme Data</title>

<programme id="1">
<programme 1>
<name>A nightmare on Elm Street</name>
<image path>../images/Elm Street.jpg</image path>
<mood>Scared</mood>
</programme 1></programme>



View




  <!DOCTYPE html>

<html>
<head>
<title></title>
</head>

<body>
<h1>Moodslider</h1>

<div class="box">
<td style="text-align: center; vertical-align: middle;">
</div>

<div class="slidecontainer">Agitated
<input type="range" min="1" max="5" value="1" class="slider" id="myRange">Calm
</div>

<div class="slidecontainer">Happy
<input type="range" min="1" max="5" value="1" class="slider" id="myRange">Sad
</div>

<div class="slidecontainer">Tired
<input type="range" min="1" max="5" value="1" class="slider" id="myRange">Wide Awake
</div>

<div class="slidecontainer">Scared
<input type="range" min="1" max="5" value="1" class="slider" id="myRange">Fearless
</div>

<form action="/action_page.php">

<input type="text" name="fname" placeholder="No content 1"><br>

<input type="text" name="lname" placeholder="No content 2"><br>

</form>

<form action="/projects/upload" method="get" enctype="multipart/form- data">Select image to upload:

<!--{{ csrf_field() }} -->
<input type="file" name="fileToUpload" id="fileToUpload">

<input type="submit" value="Upload Image" name="submit">

</form>
</body>
</html>









share|improve this question
























  • Why do you use GET instead of POST as method?
    – common sense
    Nov 20 at 22:09










  • When I originally set it up using the POST method it did not work when I submitted the form, the GET method worked.
    – Matthew Richardson
    Nov 20 at 22:14






  • 1




    You have to uncomment the csrf field {{ csrf_field() } or change it to @csrf. multipart/form-data must have no space.
    – common sense
    Nov 20 at 22:21












  • There are a few things in your code who has to be addressed. You calling the upload() method with action="/projects/upload" I suppose this works because the error is thrown, but you don't pass the $request to the method. How do you store the XML file on your filesystem?
    – common sense
    Nov 20 at 22:26










  • I hadn't included a show method within my controller, the POST method now works. With regards to where the XML file is stored, it is in my public folder.
    – Matthew Richardson
    Nov 20 at 22:31
















0














I am trying to parse the following xml and keep on running into the same error message "Unable to parse XML from string", please see the below error message.



protected function resolveXmlObject($xml): Document
{
if (! $xml) {
throw new InvalidContentException('Unable to parse XML from string.');
}

return $this->document->setContent($xml);
}


I am new to using xml and am unsure what the issue is with the code that I have provided. If someone could point me in the right direction as to what I am doing wrong that would be greatly appreciated.




Controller




use OrchestraParserXmlFacade as XmlParser;

public function upload()
{
$xml = XmlParser::load(asset('xml/data.xml'));

$user = $xml->parse([
'id' => ['uses' => 'programme::id'],
'name' => ['uses' => 'programme.name'],
]);

return view ('projects.upload', compact('user'));
}



XML




<?xml version="1.0" encoding=”UTF-8”?>

<programme data>
<title>Programme Data</title>

<programme id="1">
<programme 1>
<name>A nightmare on Elm Street</name>
<image path>../images/Elm Street.jpg</image path>
<mood>Scared</mood>
</programme 1></programme>



View




  <!DOCTYPE html>

<html>
<head>
<title></title>
</head>

<body>
<h1>Moodslider</h1>

<div class="box">
<td style="text-align: center; vertical-align: middle;">
</div>

<div class="slidecontainer">Agitated
<input type="range" min="1" max="5" value="1" class="slider" id="myRange">Calm
</div>

<div class="slidecontainer">Happy
<input type="range" min="1" max="5" value="1" class="slider" id="myRange">Sad
</div>

<div class="slidecontainer">Tired
<input type="range" min="1" max="5" value="1" class="slider" id="myRange">Wide Awake
</div>

<div class="slidecontainer">Scared
<input type="range" min="1" max="5" value="1" class="slider" id="myRange">Fearless
</div>

<form action="/action_page.php">

<input type="text" name="fname" placeholder="No content 1"><br>

<input type="text" name="lname" placeholder="No content 2"><br>

</form>

<form action="/projects/upload" method="get" enctype="multipart/form- data">Select image to upload:

<!--{{ csrf_field() }} -->
<input type="file" name="fileToUpload" id="fileToUpload">

<input type="submit" value="Upload Image" name="submit">

</form>
</body>
</html>









share|improve this question
























  • Why do you use GET instead of POST as method?
    – common sense
    Nov 20 at 22:09










  • When I originally set it up using the POST method it did not work when I submitted the form, the GET method worked.
    – Matthew Richardson
    Nov 20 at 22:14






  • 1




    You have to uncomment the csrf field {{ csrf_field() } or change it to @csrf. multipart/form-data must have no space.
    – common sense
    Nov 20 at 22:21












  • There are a few things in your code who has to be addressed. You calling the upload() method with action="/projects/upload" I suppose this works because the error is thrown, but you don't pass the $request to the method. How do you store the XML file on your filesystem?
    – common sense
    Nov 20 at 22:26










  • I hadn't included a show method within my controller, the POST method now works. With regards to where the XML file is stored, it is in my public folder.
    – Matthew Richardson
    Nov 20 at 22:31














0












0








0







I am trying to parse the following xml and keep on running into the same error message "Unable to parse XML from string", please see the below error message.



protected function resolveXmlObject($xml): Document
{
if (! $xml) {
throw new InvalidContentException('Unable to parse XML from string.');
}

return $this->document->setContent($xml);
}


I am new to using xml and am unsure what the issue is with the code that I have provided. If someone could point me in the right direction as to what I am doing wrong that would be greatly appreciated.




Controller




use OrchestraParserXmlFacade as XmlParser;

public function upload()
{
$xml = XmlParser::load(asset('xml/data.xml'));

$user = $xml->parse([
'id' => ['uses' => 'programme::id'],
'name' => ['uses' => 'programme.name'],
]);

return view ('projects.upload', compact('user'));
}



XML




<?xml version="1.0" encoding=”UTF-8”?>

<programme data>
<title>Programme Data</title>

<programme id="1">
<programme 1>
<name>A nightmare on Elm Street</name>
<image path>../images/Elm Street.jpg</image path>
<mood>Scared</mood>
</programme 1></programme>



View




  <!DOCTYPE html>

<html>
<head>
<title></title>
</head>

<body>
<h1>Moodslider</h1>

<div class="box">
<td style="text-align: center; vertical-align: middle;">
</div>

<div class="slidecontainer">Agitated
<input type="range" min="1" max="5" value="1" class="slider" id="myRange">Calm
</div>

<div class="slidecontainer">Happy
<input type="range" min="1" max="5" value="1" class="slider" id="myRange">Sad
</div>

<div class="slidecontainer">Tired
<input type="range" min="1" max="5" value="1" class="slider" id="myRange">Wide Awake
</div>

<div class="slidecontainer">Scared
<input type="range" min="1" max="5" value="1" class="slider" id="myRange">Fearless
</div>

<form action="/action_page.php">

<input type="text" name="fname" placeholder="No content 1"><br>

<input type="text" name="lname" placeholder="No content 2"><br>

</form>

<form action="/projects/upload" method="get" enctype="multipart/form- data">Select image to upload:

<!--{{ csrf_field() }} -->
<input type="file" name="fileToUpload" id="fileToUpload">

<input type="submit" value="Upload Image" name="submit">

</form>
</body>
</html>









share|improve this question















I am trying to parse the following xml and keep on running into the same error message "Unable to parse XML from string", please see the below error message.



protected function resolveXmlObject($xml): Document
{
if (! $xml) {
throw new InvalidContentException('Unable to parse XML from string.');
}

return $this->document->setContent($xml);
}


I am new to using xml and am unsure what the issue is with the code that I have provided. If someone could point me in the right direction as to what I am doing wrong that would be greatly appreciated.




Controller




use OrchestraParserXmlFacade as XmlParser;

public function upload()
{
$xml = XmlParser::load(asset('xml/data.xml'));

$user = $xml->parse([
'id' => ['uses' => 'programme::id'],
'name' => ['uses' => 'programme.name'],
]);

return view ('projects.upload', compact('user'));
}



XML




<?xml version="1.0" encoding=”UTF-8”?>

<programme data>
<title>Programme Data</title>

<programme id="1">
<programme 1>
<name>A nightmare on Elm Street</name>
<image path>../images/Elm Street.jpg</image path>
<mood>Scared</mood>
</programme 1></programme>



View




  <!DOCTYPE html>

<html>
<head>
<title></title>
</head>

<body>
<h1>Moodslider</h1>

<div class="box">
<td style="text-align: center; vertical-align: middle;">
</div>

<div class="slidecontainer">Agitated
<input type="range" min="1" max="5" value="1" class="slider" id="myRange">Calm
</div>

<div class="slidecontainer">Happy
<input type="range" min="1" max="5" value="1" class="slider" id="myRange">Sad
</div>

<div class="slidecontainer">Tired
<input type="range" min="1" max="5" value="1" class="slider" id="myRange">Wide Awake
</div>

<div class="slidecontainer">Scared
<input type="range" min="1" max="5" value="1" class="slider" id="myRange">Fearless
</div>

<form action="/action_page.php">

<input type="text" name="fname" placeholder="No content 1"><br>

<input type="text" name="lname" placeholder="No content 2"><br>

</form>

<form action="/projects/upload" method="get" enctype="multipart/form- data">Select image to upload:

<!--{{ csrf_field() }} -->
<input type="file" name="fileToUpload" id="fileToUpload">

<input type="submit" value="Upload Image" name="submit">

</form>
</body>
</html>






php xml laravel






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 at 21:16









Ross Wilson

15.5k22539




15.5k22539










asked Nov 20 at 21:09









Matthew Richardson

266




266












  • Why do you use GET instead of POST as method?
    – common sense
    Nov 20 at 22:09










  • When I originally set it up using the POST method it did not work when I submitted the form, the GET method worked.
    – Matthew Richardson
    Nov 20 at 22:14






  • 1




    You have to uncomment the csrf field {{ csrf_field() } or change it to @csrf. multipart/form-data must have no space.
    – common sense
    Nov 20 at 22:21












  • There are a few things in your code who has to be addressed. You calling the upload() method with action="/projects/upload" I suppose this works because the error is thrown, but you don't pass the $request to the method. How do you store the XML file on your filesystem?
    – common sense
    Nov 20 at 22:26










  • I hadn't included a show method within my controller, the POST method now works. With regards to where the XML file is stored, it is in my public folder.
    – Matthew Richardson
    Nov 20 at 22:31


















  • Why do you use GET instead of POST as method?
    – common sense
    Nov 20 at 22:09










  • When I originally set it up using the POST method it did not work when I submitted the form, the GET method worked.
    – Matthew Richardson
    Nov 20 at 22:14






  • 1




    You have to uncomment the csrf field {{ csrf_field() } or change it to @csrf. multipart/form-data must have no space.
    – common sense
    Nov 20 at 22:21












  • There are a few things in your code who has to be addressed. You calling the upload() method with action="/projects/upload" I suppose this works because the error is thrown, but you don't pass the $request to the method. How do you store the XML file on your filesystem?
    – common sense
    Nov 20 at 22:26










  • I hadn't included a show method within my controller, the POST method now works. With regards to where the XML file is stored, it is in my public folder.
    – Matthew Richardson
    Nov 20 at 22:31
















Why do you use GET instead of POST as method?
– common sense
Nov 20 at 22:09




Why do you use GET instead of POST as method?
– common sense
Nov 20 at 22:09












When I originally set it up using the POST method it did not work when I submitted the form, the GET method worked.
– Matthew Richardson
Nov 20 at 22:14




When I originally set it up using the POST method it did not work when I submitted the form, the GET method worked.
– Matthew Richardson
Nov 20 at 22:14




1




1




You have to uncomment the csrf field {{ csrf_field() } or change it to @csrf. multipart/form-data must have no space.
– common sense
Nov 20 at 22:21






You have to uncomment the csrf field {{ csrf_field() } or change it to @csrf. multipart/form-data must have no space.
– common sense
Nov 20 at 22:21














There are a few things in your code who has to be addressed. You calling the upload() method with action="/projects/upload" I suppose this works because the error is thrown, but you don't pass the $request to the method. How do you store the XML file on your filesystem?
– common sense
Nov 20 at 22:26




There are a few things in your code who has to be addressed. You calling the upload() method with action="/projects/upload" I suppose this works because the error is thrown, but you don't pass the $request to the method. How do you store the XML file on your filesystem?
– common sense
Nov 20 at 22:26












I hadn't included a show method within my controller, the POST method now works. With regards to where the XML file is stored, it is in my public folder.
– Matthew Richardson
Nov 20 at 22:31




I hadn't included a show method within my controller, the POST method now works. With regards to where the XML file is stored, it is in my public folder.
– Matthew Richardson
Nov 20 at 22:31












1 Answer
1






active

oldest

votes


















0














The call to asset('xml/data.xml') does not give you a file or an internal path, it gives you the public URL to the file inside the public folder. Try it with public_path('xml/data.xml').



https://laravel.com/docs/5.7/helpers#method-public-path



E.g.



$xml = XmlParser::load(public_path('xml/data.xml'));






share|improve this answer























  • Hi, I have added this to my code and the same error message still persists.
    – Matthew Richardson
    Nov 20 at 21:47










  • Is the file you want inside the public folder? There are different helpers if it's in storage or app etc.
    – newUserName02
    Nov 20 at 21:55










  • Yes, it is in the public folder
    – Matthew Richardson
    Nov 20 at 22:06










  • What does public_path('xml/data.xml') return? Add dd(public_path('xml/data.xml')) above the line where you load the XML. Add the result to you question.
    – common sense
    Nov 20 at 22:11











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53401572%2ferror-when-trying-to-parse-xml-using-laravel%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














The call to asset('xml/data.xml') does not give you a file or an internal path, it gives you the public URL to the file inside the public folder. Try it with public_path('xml/data.xml').



https://laravel.com/docs/5.7/helpers#method-public-path



E.g.



$xml = XmlParser::load(public_path('xml/data.xml'));






share|improve this answer























  • Hi, I have added this to my code and the same error message still persists.
    – Matthew Richardson
    Nov 20 at 21:47










  • Is the file you want inside the public folder? There are different helpers if it's in storage or app etc.
    – newUserName02
    Nov 20 at 21:55










  • Yes, it is in the public folder
    – Matthew Richardson
    Nov 20 at 22:06










  • What does public_path('xml/data.xml') return? Add dd(public_path('xml/data.xml')) above the line where you load the XML. Add the result to you question.
    – common sense
    Nov 20 at 22:11
















0














The call to asset('xml/data.xml') does not give you a file or an internal path, it gives you the public URL to the file inside the public folder. Try it with public_path('xml/data.xml').



https://laravel.com/docs/5.7/helpers#method-public-path



E.g.



$xml = XmlParser::load(public_path('xml/data.xml'));






share|improve this answer























  • Hi, I have added this to my code and the same error message still persists.
    – Matthew Richardson
    Nov 20 at 21:47










  • Is the file you want inside the public folder? There are different helpers if it's in storage or app etc.
    – newUserName02
    Nov 20 at 21:55










  • Yes, it is in the public folder
    – Matthew Richardson
    Nov 20 at 22:06










  • What does public_path('xml/data.xml') return? Add dd(public_path('xml/data.xml')) above the line where you load the XML. Add the result to you question.
    – common sense
    Nov 20 at 22:11














0












0








0






The call to asset('xml/data.xml') does not give you a file or an internal path, it gives you the public URL to the file inside the public folder. Try it with public_path('xml/data.xml').



https://laravel.com/docs/5.7/helpers#method-public-path



E.g.



$xml = XmlParser::load(public_path('xml/data.xml'));






share|improve this answer














The call to asset('xml/data.xml') does not give you a file or an internal path, it gives you the public URL to the file inside the public folder. Try it with public_path('xml/data.xml').



https://laravel.com/docs/5.7/helpers#method-public-path



E.g.



$xml = XmlParser::load(public_path('xml/data.xml'));







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 20 at 21:43

























answered Nov 20 at 21:34









newUserName02

55849




55849












  • Hi, I have added this to my code and the same error message still persists.
    – Matthew Richardson
    Nov 20 at 21:47










  • Is the file you want inside the public folder? There are different helpers if it's in storage or app etc.
    – newUserName02
    Nov 20 at 21:55










  • Yes, it is in the public folder
    – Matthew Richardson
    Nov 20 at 22:06










  • What does public_path('xml/data.xml') return? Add dd(public_path('xml/data.xml')) above the line where you load the XML. Add the result to you question.
    – common sense
    Nov 20 at 22:11


















  • Hi, I have added this to my code and the same error message still persists.
    – Matthew Richardson
    Nov 20 at 21:47










  • Is the file you want inside the public folder? There are different helpers if it's in storage or app etc.
    – newUserName02
    Nov 20 at 21:55










  • Yes, it is in the public folder
    – Matthew Richardson
    Nov 20 at 22:06










  • What does public_path('xml/data.xml') return? Add dd(public_path('xml/data.xml')) above the line where you load the XML. Add the result to you question.
    – common sense
    Nov 20 at 22:11
















Hi, I have added this to my code and the same error message still persists.
– Matthew Richardson
Nov 20 at 21:47




Hi, I have added this to my code and the same error message still persists.
– Matthew Richardson
Nov 20 at 21:47












Is the file you want inside the public folder? There are different helpers if it's in storage or app etc.
– newUserName02
Nov 20 at 21:55




Is the file you want inside the public folder? There are different helpers if it's in storage or app etc.
– newUserName02
Nov 20 at 21:55












Yes, it is in the public folder
– Matthew Richardson
Nov 20 at 22:06




Yes, it is in the public folder
– Matthew Richardson
Nov 20 at 22:06












What does public_path('xml/data.xml') return? Add dd(public_path('xml/data.xml')) above the line where you load the XML. Add the result to you question.
– common sense
Nov 20 at 22:11




What does public_path('xml/data.xml') return? Add dd(public_path('xml/data.xml')) above the line where you load the XML. Add the result to you question.
– common sense
Nov 20 at 22:11


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53401572%2ferror-when-trying-to-parse-xml-using-laravel%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

To store a contact into the json file from server.js file using a class in NodeJS

Redirect URL with Chrome Remote Debugging Android Devices

Dieringhausen