1

I'm working on DomDocument to build my XML. I need to output this header:

<p:FatturaElettronica versione="FPR12" xsi:schemaLocation="http://ivaservizi.agenziaentrate.gov.it/docs/xsd/fatture/v1.2 http://www.fatturapa.gov.it/export/fatturazione/sdi/fatturapa/v1.2/Schema_del_file_xml_FatturaPA_versione_1.2.xsd"> 

To achieve this result I have written this code:

$dom = new \DomDocument("1.0", "UTF-8"); $init = $dom->createElementNS('http://www.example.com/XFoo', 'p:FatturaElettronica'); $init->setAttributeNS('http://www.w3.org/2000/xmlns/' ,'xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance'); $init->setAttributeNS('http://www.w3.org/2001/XMLSchema-instance', 'schemaLocation', 'http://ivaservizi.agenziaentrate.gov.it/docs/xsd/fatture/v1.2 http://www.fatturapa.gov.it/export/fatturazione/sdi/fatturapa/v1.2/Schema_del_file_xml_FatturaPA_versione_1.2.xsd'); $version = "FPR12"; $init->appendChild($dom->createAttribute('versione'))->appendChild($dom->createTextNode($version)); 

But the output is this:

 <p:FatturaElettronica xmlns:p="http://www.example.com/XFoo" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://ivaservizi.agenziaentrate.gov.it/docs/xsd /fatture/v1.2 http://www.fatturapa.gov.it/export/fatturazione /sdi/fatturapa/v1.2/Schema_del_file_xml_FatturaPA_versione_1.2.xsd" versione="FPR12"> 

Where am I wrong?

1 Answer 1

1

Where am I wrong?

It's your goal that's wrong. Namespace prefixes must be declared if used. The XML in your goal uses namespaces prefixes but never declares them. This would leave the XML not namespace-well-formed.

The output that you are generating is namespace-well-formed and is what you should produce.

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

1 Comment

Sounds good: this is a copy/paste from Italian governement site.... fatturapa.gov.it/export/fatturazione/sdi/fatturapa/v1.2/….... let me try to change output

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.