problems with xmlDomDocument.loadXML('')

benteebentee Posts: 14Member
Hi all,

I'm using Navision 3.70. And are generating an xml-file like this:

START:
variable
Var Name DataType Subtype Length
Ja CurrNode Automation 'Microsoft XML, v4.0'.IXMLDOMNode
Name DataType Subtype Length
xmlInvoice Automation 'Microsoft XML, v4.0'.DOMDocument30
objPI Automation 'Microsoft XML, v4.0'.IXMLDOMProcessingInstruction


CREATE(xmlInvoice);
xmlInvoice.async := FALSE;
xmlInvoice.loadXML('<pidx:Invoice></pidx:Invoice>');

objPI := xmlInvoice.createProcessingInstruction('xml','version="1.0" encoding="ISO-8859-1"');
CurrNode := xmlInvoice.documentElement;
xmlInvoice.insertBefore(objPI,CurrNode);

xmlInvoice.documentElement.setAttribute('xmlns','http://www.api.org/pidXML/v1.0');
xmlInvoice.documentElement.setAttribute('xmlns:xsi','http://www.w3.org/2001/XMLSchema-instance');
xmlInvoice.documentElement.setAttribute('xmlns:pidx','"http://www.api.org/pidXML/v1.0');
xmlInvoice.documentElement.setAttribute('xsi:schemaLocation',
'http://www.api.org/pidXML/v1.0 C:\PIDX\Invoice-2002-02-14-V1-0.xsd');
xmlInvoice.documentElement.setAttribute('pidx:transactionPurposeIndicator','Original');
xmlInvoice.documentElement.setAttribute('pidx:version','1.0');

CurrNode := xmlInvoice.documentElement;
END

Of course there's more code :),but my problem is the loadxml('<pidx:Invoice></pidx:Invoice>); it seems like it will not accept the : character. Everthing works fine if I use any other character, or just <pidx Invoice></Pidx Invoice>, without the : .

Does anyone have a clue how to solve this?

Regards
Bente

Answers

  • ara3nara3n Posts: 9,132Member
    I suggest to make a change in your code to the following.

    xmlInvoice.loadXML('<?xml version="1.0" encoding="ISO-8859-1"?>' +
    '<pidx:Invoice></pidx:Invoice>');


    and remove

    objPI := xmlInvoice.createProcessingInstruction('xml','version="1.0" encoding="ISO-8859-1"');
    CurrNode := xmlInvoice.documentElement;
    xmlInvoice.insertBefore(objPI,CurrNode);
  • benteebentee Posts: 14Member
    Thanks, but it's not working :cry: . It then get problems with the next line AddElement('xmlns','http://www.api.org/pidXML/v1.0'), and gives error
    "This Automation variable has not been instantiated. You can instantiate it by either creating or assigning it"

    Bent
  • benteebentee Posts: 14Member
    It works fine if I don't use the prefix pidx: in front of Invoice...

    Regards,
    Bente
  • ara3nara3n Posts: 9,132Member
    which line does it error and can you paste your new code?

    Thanks.
  • benteebentee Posts: 14Member
    It gives error on the first setAttribute. I also tried to rearrange them, and leave some out, but it won't help.

    CREATE(xmlInvoice);
    xmlInvoice.async := FALSE;

    xmlInvoice.loadXML('<?xml version="1.0" encoding="ISO-8859-1"?>' +
    '<pidx:Invoice></pidx:Invoice>');

    xmlInvoice.documentElement.setAttribute('xmlns','http://www.api.org/pidXML/v1.0');
    xmlInvoice.documentElement.setAttribute('xmlns:xsi','http://www.w3.org/2001/XMLSchema-instance');
    xmlInvoice.documentElement.setAttribute('xmlns:pidx','http://www.api.org/pidXML/v1.0');
    xmlInvoice.documentElement.setAttribute('xsi:schemaLocation',
    'http://www.api.org/pidXML/v1.0 C:\PIDX\Invoice-2002-02-14-V1-0.xsd');
    xmlInvoice.documentElement.setAttribute('pidx:transactionPurposeIndicator','Original');
    xmlInvoice.documentElement.setAttribute('pidx:version','1.0');


    CurrNode := xmlInvoice.documentElement;

    thanks
  • ta5ta5 Posts: 1,329Member
    Try this:
    // xmlProcessingInst: 'Microsoft XML, v6.0'.IXMLDOMProcessingInstruction
    // CurrNode: 'Microsoft XML, v6.0'.IXMLDOMNode
    
    CREATE(xmlInvoice);
    xmlInvoice.async := FALSE;
    xmlProcessingInst:= xmlInvoice.createProcessingInstruction('xml','version="1.0" encoding="ISO-8859-1"');
    CurrNode := xmlInvoice.appendChild(xmlProcessingInst);
    CurrNode := xmlInvoice.createElement('pidx:Invoice');
    CurrNode := xmlInvoice.appendChild(CurrNode);
    
    xmlInvoice.documentElement.setAttribute('xmlns','http://www.api.org/pidXML/v1.0');
    xmlInvoice.documentElement.setAttribute('xmlns:xsi','http://www.w3.org/2001/XMLSchema-instance');
    xmlInvoice.save('c:\temp\myFile.xml');
    

    Hope this helps.
    Thomas
  • benteebentee Posts: 14Member
    Oh, my, it worked!!!!! You really made my day!!! =D> =D> =D>

    Thank you so much!!

    Best regards,
    Bente
  • ta5ta5 Posts: 1,329Member
    bentee wrote:
    Oh, my, it worked!!!!! You really made my day!!! =D> =D> =D>

    Thank you so much!!

    Best regards,
    Bente

    Glad to help!
Sign In or Register to comment.