Skip to content

Namespace Creation Error #1900

@ABaludin

Description

@ABaludin

Hello!
I need to create next XML document :

<?xml version="1.0" encoding="UTF-8"?> <signed xmlns="urn:x-obml:1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="CMSDETACHED"></signed>

So I create next code:

   `xmlDoc := XmlDocument.Create;
    xmlDec := xmlDeclaration.Create('1.0','UTF-8','');
    xmlDoc.SetDeclaration(xmlDec);

    XmlElm := XmlElement.Create('signed');
    xmlAtt := XmlAttribute.Create('xmlns', 'urn:x-obml:1.0');
    xmlElm.Add(xmlAtt);
    xmlAtt := XmlAttribute.Create('xsi', 'xmlns', 'http://www.w3.org/2001/XMLSchema-instance');
    xmlElm.Add(xmlAtt);
    xmlAtt := XmlAttribute.Create('type', 'xsi', 'CMSDETACHED');
    xmlElm.Add(xmlAtt);

    xmlDoc.Add(xmlElm);
    xmlDoc.WriteTo(XMLText);

    exit(XMLText);`

But on xmlDoc.WriteTo(XMLText); row i've got next exception:

The following exception was encountered when processing XML data: 'The prefix '' cannot be redefined from '' to 'urn:x-obml:1.0' within the same start element tag.' at line 0 and position 0.

What's the problem?

Changing to
xmlAtt := XmlAttribute.CreateNamespaceDeclaration('xmlns', 'urn:x-obml:1.0');

goes to exception

Exception of type 'Microsoft.Dynamics.Nav.Types.Exceptions.NavNCLArgumentException' was thrown.

and docs told that

If the prefix is xmlns, then this parameter must be http://www.w3.org/2000/xmlns/; otherwise an exception is thrown.

but i have to have xmlns="urn:x-obml:1.0" because of it's API requirement.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions