Neiopai Posted March 13, 2013 Share Posted March 13, 2013 (edited) Hi guys . My name is Ricado Baptista i am new here and i have a problem, I got this code: <html> <head> </head> <body > <?php header('Content-type: text/xml'); $xml = simplexml_load_file("saft_solverde_wgres_FAC2-01-2013-500272484.xml"); foreach($xml->Invoice as $Invoice) { echo $InvoiceNo->InvoiceNo; } ?> </body> </html> But when i run it i go this: "This XML file does not appear to have any style information associated with it. The document tree is shown below. <html> <head></head> <body></body> </html> Why nothing is appearing? where is my error? :/ Edited March 14, 2013 by ignace Added code tags Quote Link to comment https://forums.phpfreaks.com/topic/275593-xml-on-php-need-help/ Share on other sites More sharing options...
ScottBaxter Posted March 13, 2013 Share Posted March 13, 2013 It doesn't look like your formatting it correctly. Try putting this in: print '<?xml version="1.0" encoding="ISO-8859-1"?>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/275593-xml-on-php-need-help/#findComment-1418338 Share on other sites More sharing options...
Neiopai Posted March 13, 2013 Author Share Posted March 13, 2013 This page contains the following errors: error on line 5 at column 6: XML declaration allowed only at the start of the document Below is a rendering of the page up to the first error.I get this . Quote Link to comment https://forums.phpfreaks.com/topic/275593-xml-on-php-need-help/#findComment-1418340 Share on other sites More sharing options...
ScottBaxter Posted March 13, 2013 Share Posted March 13, 2013 Get rid of the HTML entries at the top. :-) Quote Link to comment https://forums.phpfreaks.com/topic/275593-xml-on-php-need-help/#findComment-1418342 Share on other sites More sharing options...
Neiopai Posted March 13, 2013 Author Share Posted March 13, 2013 (edited) <body > <?php header('Content-type: text/xml'); $xml = simplexml_load_file("saft_solverde_wgres_FAC2-01-2013-500272484.xml"); foreach($xml->Invoice as $Invoice) { echo $InvoiceNo->InvoiceNo; } print '<?xml version="1.0" encoding="ISO-8859-1"?>';?> </body> </html> like this? Sorry my php skills are not the best If i run this code i get : This page contains the following errors: error on line 2 at column 6: XML declaration allowed only at the start of the document Below is a rendering of the page up to the first error. Edited March 14, 2013 by ignace Adding code tags Quote Link to comment https://forums.phpfreaks.com/topic/275593-xml-on-php-need-help/#findComment-1418344 Share on other sites More sharing options...
ScottBaxter Posted March 13, 2013 Share Posted March 13, 2013 <?php print '<?xml version="1.0" encoding="utf-8"?>';?> $xml = simplexml_load_file("saft_solverde_wgres_FAC2-01-2013-500272484.xml"); foreach($xml->Invoice as $Invoice) { echo $InvoiceNo->InvoiceNo; } try that... You might need to find out from the XML file what encoding it has. Quote Link to comment https://forums.phpfreaks.com/topic/275593-xml-on-php-need-help/#findComment-1418345 Share on other sites More sharing options...
Neiopai Posted March 13, 2013 Author Share Posted March 13, 2013 the encoding is windows-1252 But when i place the code you gave me and try to run the php i got: $xml = simplexml_load_file("saft_solverde_wgres_FAC2-01-2013-500272484.xml"); foreach($xml->Invoice as $Invoice) { echo $InvoiceNo->InvoiceNo; } Quote Link to comment https://forums.phpfreaks.com/topic/275593-xml-on-php-need-help/#findComment-1418346 Share on other sites More sharing options...
Neiopai Posted March 14, 2013 Author Share Posted March 14, 2013 No one know the error? Quote Link to comment https://forums.phpfreaks.com/topic/275593-xml-on-php-need-help/#findComment-1418552 Share on other sites More sharing options...
JLT Posted March 14, 2013 Share Posted March 14, 2013 the encoding is windows-1252 But when i place the code you gave me and try to run the php i got: $xml = simplexml_load_file("saft_solverde_wgres_FAC2-01-2013-500272484.xml"); foreach($xml->Invoice as $Invoice) { echo $InvoiceNo->InvoiceNo; } The reason you got the above, is because in the snippet you were given previously by ScottBaxter, on line 2 at the end is a php close tag (?>) and thus everything placed after it is treated as regular HTML. You need to remove that close tag as it is inappropriately placed. Having a good code editor would of easily pointed this out to you. I suggest Notepad++ and specify the document "Language" as PHP. Quote Link to comment https://forums.phpfreaks.com/topic/275593-xml-on-php-need-help/#findComment-1418553 Share on other sites More sharing options...
Neiopai Posted March 14, 2013 Author Share Posted March 14, 2013 (edited) Code: <html> <head> </head> <body > <?php print '<?xml version="1.0" encoding="windows-1252"?>'; header('Content-type: text/xml encoding="windows-1252"'); $xml = simplexml_load_file("saft_solverde_wgres_FAC2-01-2013-500272484.xml"); foreach($xml->Invoice as $Invoice) { echo $InvoiceNo->InvoiceNo; } ?> </body> </html> Error: This page contains the following errors: error on line 5 at column 6: XML declaration allowed only at the start of the document Below is a rendering of the page up to the first error. Line 5 is the "<?php" I start using notepad++ 2 days ago . still learning how to use it . but the language is set to php Edited March 14, 2013 by ignace Adding code tags Quote Link to comment https://forums.phpfreaks.com/topic/275593-xml-on-php-need-help/#findComment-1418561 Share on other sites More sharing options...
ignace Posted March 14, 2013 Share Posted March 14, 2013 XML and HTML are different formats. When you output XML there should be no HTML involved. Like ScottBaxter already mentioned is that you need to remove ALL HTML which you have failed to do so far. Your code contained a bunch of errors, so buying a book on PHP and reading it will help you in understanding what you are writing and will also give you a basic understanding of debugging. <?php header('Content-type: text/xml; charset=windows-1252'); print '<?xml version="1.0"?>'; $xml = simplexml_load_file("saft_solverde_wgres_FAC2-01-2013-500272484.xml"); foreach($xml->Invoice as $Invoice) { echo $Invoice->InvoiceNo; } Quote Link to comment https://forums.phpfreaks.com/topic/275593-xml-on-php-need-help/#findComment-1418589 Share on other sites More sharing options...
Neiopai Posted March 14, 2013 Author Share Posted March 14, 2013 Thanks for the help ignace. after i placed your code i got this error . This page contains the following errors:error on line 1 at column 21: Extra content at the end of the document Below is a rendering of the page up to the first error. Sorry but i never worked with xml and my php knowledge is pretty basic. Thanks for all the help so far. Quote Link to comment https://forums.phpfreaks.com/topic/275593-xml-on-php-need-help/#findComment-1418598 Share on other sites More sharing options...
ignace Posted March 14, 2013 Share Posted March 14, 2013 It appears I was confused about your intentions. <!doctype html> <html> <head> <meta charset="utf-8"> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <title>Invoices</title> </head> <body> <?php $xml = simplexml_load_file("saft_solverde_wgres_FAC2-01-2013-500272484.xml"); foreach($xml->Invoice as $Invoice) { echo $Invoice->InvoiceNo . '<br>'; } ?> </body> </html>Try that. Quote Link to comment https://forums.phpfreaks.com/topic/275593-xml-on-php-need-help/#findComment-1418614 Share on other sites More sharing options...
Neiopai Posted March 14, 2013 Author Share Posted March 14, 2013 With that code i get a white page . No error , no code , no xml , just .. white Already try to change the code in all of the things i can get and always torn up a white page. Quote Link to comment https://forums.phpfreaks.com/topic/275593-xml-on-php-need-help/#findComment-1418631 Share on other sites More sharing options...
ignace Posted March 14, 2013 Share Posted March 14, 2013 Start debugging, why does it not print anything on screen. Using var_dump you can print the type of a variable to screen like shown in the below example: <!doctype html> <html> <head> <meta charset="utf-8"> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <title>Invoices</title> </head> <body> <?php $xml = simplexml_load_file("saft_solverde_wgres_FAC2-01-2013-500272484.xml"); echo '$xml->Invoice: '; var_dump($xml->Invoice); foreach($xml->Invoice as $Invoice) { echo $Invoice->InvoiceNo . '<br>'; } ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/275593-xml-on-php-need-help/#findComment-1418636 Share on other sites More sharing options...
Neiopai Posted March 18, 2013 Author Share Posted March 18, 2013 Sorry for the late replay object(SimpleXMLElement)#2 (0) { } I search on google , got a few answers like this one: "This is because SimpleXML requires exact typecasting or you'll get ridiculous things happening like this - var_dump will output what you want, echo won't" But .. i dont understand what it mean or how to apply on my code i mean. i have to remove the echo and switch to one var_dump? Quote Link to comment https://forums.phpfreaks.com/topic/275593-xml-on-php-need-help/#findComment-1419291 Share on other sites More sharing options...
Neiopai Posted March 19, 2013 Author Share Posted March 19, 2013 (edited) I change my code. now i am using strings and it works . well it print one of the invoice but i need to print all not just one . This is my code <?php $filename = 'saft_solverde_wgres_FAC2-01-2013-500272484.xml'; $xml = simplexml_load_file($filename); $p_cnt = count($xml->SourceDocuments->SalesInvoices->Invoice->InvoiceNo); for($i = 0; $i < $p_cnt; $i++) { $Invoice = $xml->SourceDocuments->SalesInvoices->Invoice->InvoiceNo[$i]; echo $Invoice; } ?> This is the what i get 01 22/20367[/size] And its right. this is the invoiceNo. [/size] How can i place it in a way that prints every invoice and not just one? [/size] Edited March 19, 2013 by ignace Quote Link to comment https://forums.phpfreaks.com/topic/275593-xml-on-php-need-help/#findComment-1419504 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.