[solved]XML namespace qualifiers

ta5ta5 Member Posts: 1,164
Hello

I want to create an xml file like this:
<?xml version="1.0" encoding="UTF-8" ?> 
<foo-0001:envelope version="1.0" xmlns:foo-0001="http://www.foo.com/xmlns/foo-0001/1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <messageId>1234</messageId> 
</foo-0001:envelope>

So far the following code works, but the element "messageId" is written as "<messageId>, not as "<foo-0001:messageId>"
CREATE(xmlDoc);
xmlMgt.SetNormalCase;
xmlProcessingInst:=xmlDoc.createProcessingInstruction('xml','version="1.0" encoding="UTF-8"');

CurrNode := xmlDoc.appendChild(xmlProcessingInst);
CurrNode := xmlDoc.createElement('foo-0001:envelope');
CurrNode := xmlDoc.appendChild(CurrNode);

xmlMgt.AddAttribute(CurrNode,'version','1.0');
xmlMgt.AddAttribute(CurrNode,'xmlns:foo-0001','http://www.foo.com/xmlns/foo-0001/1');
xmlMgt.AddAttribute(CurrNode,'xmlns:xsi','http://www.w3.org/2001/XMLSchema-instance');

xmlMgt.AddElement(CurrNode,'messageId','1234','',NewChild);

When I use
xmlMgt.AddElement(CurrNode,'foo-0001:messageId','1234','',NewChild);
I get the error "Reference to undeclared namespace prefix 'foo-0001'.


Any ideas? Thank you in advance.
Thomas

Comments

  • ta5ta5 Member Posts: 1,164
    I found the solution \:D/


    In cu6224, function AddElement it's better to use "createElement" instead of "createnode".
    (Of course I use now a copy of the AddElement-Function.)


    Hope this may be helpful for someone else.
    Regards
    Thomas
Sign In or Register to comment.