This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Problem with simpleXML and entity not being defined
I have this tag with an entity in an xml file:
<comune>Forli'</comune>
Simple xml in php fail to parse the file:
Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: parser error : Entity 'igrave' not defined
How can i do?
I tried this a small example and it worked for me
XML:
<?xml version="1.0" encoding="UTF-8"?>
<comune>
<comune>Forli'</comune>
</comune>
PHP:
$xml = simplexml_load_file('test.xml');
foreach($xml->children() as $child){
echo '<pre>';
print_r((string)$child);
echo '</pre>asd';
}
OUTPUT:
Forli'
Check this solution for help
Related
This question already has answers here:
How to parse XML with namespace?
(1 answer)
Parse XML namespaces with php SimpleXML
(2 answers)
Closed 2 years ago.
so I have a XML invoice and I want to access the data in it and I am absolutely clueless on how to do it. I tried following various guides online and nothing works, I get zero errors but zero results.
How can I get data from "inv:invoiceType" tag of this xml file? Thanks!
The XML is this:
<?xml version="1.0" encoding="UTF-8"?>
<dat:dataPack id="fa001" application="StwTest" version="2.0" note="Import" xmlns:dat="http://www.stormware.cz/schema/version_2/data.xsd" xmlns:inv="http://www.stormware.cz/schema/version_2/invoice.xsd" xmlns:typ="http://www.stormware.cz/schema/version_2/type.xsd">
<dat:dataPackItem id="20007" version="2.0">
<inv:invoice version="2.0">
<inv:invoiceHeader>
<inv:invoiceType>issuedInvoice</inv:invoiceType>
<inv:number>
<typ:numberRequested>20007</typ:numberRequested>
</inv:number>
<inv:paymentType>
<typ:paymentType>draft</typ:paymentType>
</inv:paymentType>
<inv:carrier>
<typ:ids>magic horse</typ:ids>
</inv:carrier>
<inv:numberOrder>20007</inv:numberOrder>
<inv:symVar>20007</inv:symVar>
<inv:date>2020-05-11</inv:date>
<inv:dateTax>2020-05-13</inv:dateTax>
<inv:dateDue>2020-05-27</inv:dateDue>
</inv:invoiceHeader>
</inv:invoice>
</dat:dataPackItem>
</dat:dataPack>
try using SimpleXML if you are not using it.
you can follow this document : Basic SimpleXML usage
This question already has answers here:
Extra content at the end of the document PHP and XML
(3 answers)
Closed 5 years ago.
As you can see I tries to make a very simple XML example with PHP. My problem is that at the end, at </users> I get an XML Parsing Error: not well-formed and I do not understand why since I do not use any special characters or any URLs. Does anyone have any ideas what the problem might be?
<?php
header('Content-type: text/xml');
$xml = "<?xml version=\"1.0\" ?>\n";
$xml .= "<users>\n";
$xml .= "test\n";
$xml .="</users>";
echo $xml;
?>
Problem solved. The solution was posted in this thread: Extra content at the end of the document PHP and XML
In short, I had to open the file with HexEdit and delete some characters.
This question already has answers here:
PHP SimpleXML get innerXML
(11 answers)
Closed 6 years ago.
I am using PHP SimpleXML to parse data in a file. Say for example I have the following XML content:
<?xml version="1.0" ?>
<root>
<parent1>
<child1>blah</child1>
<child2>blah blah</child2>
</parent1>
<parent2>blah</parent2>
</root>
I basically want to get the actual raw content of the inside of a node. I.e. I need it to return the "innerXML" of parent1 just as text, tags and all. Having trouble getting PHP to do this. Help?
For getting the exact content '<child1>blah</child1><child2>blah blah</child2>' as itself you better put them under <![CDATA[]]> Then you can get any thing inside that as iself.
xml should be like this::
<?xml version="1.0" ?>
<root>
<parent1>
<![CDATA[<child1>blah</child1>
<child2>blah blah</child2>]]>
</parent1>
<parent2>blah</parent2>
</root>
Then
$xml = simplexml_load_string($xmlstring, 'SimpleXMLElement', LIBXML_NOCDATA);
$parent1 = $xml->parent1->asXml();
echo "<pre>";echo ($parent1);echo "<pre>";
This will output :
<child1>blah</child1>
<child2>blah blah</child2>
This question already has an answer here:
Get root node of XML doc using simplexml
(1 answer)
Closed 8 years ago.
Having an issue echo'ing xml tags.
PHP:
$xml = $insureFormResult->returned;
$xml1 = new SimpleXMLElement($xml);
$result = $xml1->xpath("response")[0];
echo $result;
If I echo $xml it gives me:
<?xml version="1.0" encoding="utf-8"?>
<response>
<errors>
<error code="7">Your details are already in our system and have been forwarded to our insurance partners who will contact you shortly</error>
</errors>
</response>
The xml will always have one response tag. I also want to know how to echo the tag with id 'code'. I tried the php above but there's no result echoed.
Any kind of help will be appreciated!
EDIT
It wasn't working because of the version of PHP on my server.
I'm not really familiar with PHP, but the xpath to access the error with attribute code with value 7 is:
/response/errors/error[#code='7']
This question already has answers here:
How do you parse and process HTML/XML in PHP?
(31 answers)
Closed 9 years ago.
I have this xml content. I need to get the value from the fullName attribute. I have tried it using lib.xml parser. But it is not working. Could you please help me to achieve this? Thanks in advance.
<?xml version="1.0" encoding="UTF-8"?><currentUserDetails firstName="3rdParty" fullName="3rdParty Access" lastName="Access" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="" xmlns=""/>
Use simplexml:
$xml = simplexml_load_string($x); // assuming XML in $x
echo $xml['fullName'];
See it working: http://codepad.viper-7.com/7KVHcU
$xmlFile = "http://www.domaine.com/city.xml";
$data = simplexml_load_file($xmlFile);
print_r($data);