1

I want to create an xml document using MSXML2_TLB in delphi 5. The output should look below xml, Any idea how to do this ? I am stuck on the first line with namespace, the rest of the nodes I figured out.

<Submission xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="layout.xsd">
    <T619>
        <trnmtr_nbr>SDX123654</trnmtr_nbr>
        <sbmt_ref_id>556452</sbmt_ref_id>
        <trnmtr_tcd>3</trnmtr_tcd>
        <summ_cnt>000001</summ_cnt>
        <TRNMTR_NM>
            <l1_nm>Test Company</l1_nm>
        </TRNMTR_NM>
        <TRNMTR_ADDR>
            <addr_l1_txt>470 Nowhere RD</addr_l1_txt>
            <cty_nm>Toronto</cty_nm>
            <prov_cd>ON</prov_cd>
            <cntry_cd>CAN</cntry_cd>
            <pstl_cd>M112YY</pstl_cd>
        </TRNMTR_ADDR>
        <CNTC>
            <cntc_nm>Jhon Doe</cntc_nm>
            <cntc_area_cd>905</cntc_area_cd>
            <cntc_phn_nbr>555-5555</cntc_phn_nbr>
        </CNTC>
        <rpt_tcd>O</rpt_tcd>
        <lang_cd>E</lang_cd>
    </T619>
<Submission>
Ken White
  • 123,280
  • 14
  • 225
  • 444
S Siddiqui
  • 11
  • 1
  • You can add any attributes you want to an XML node, even ones with namespace prefixes. In this case, you would simply add one attribute with a name of `'xmlns:xsi'` and a value of `'http://www.w3.org/2001/XMLSchema-instance'`, and another attribute with a name of `'xsi:noNamespaceSchemaLocation'` and a value of `'layout.xsd'`. What is the actual problem you are having with doing that? Please show your actual code. – Remy Lebeau Feb 04 '21 at 19:12

1 Answers1

0

Thanks a lot for you help I am able to add the attribute using following code:

FDoc := CoDOMDocument30.Create();
FDoc.Async := false;
FSubmission := FDoc.CreateElement('Submission');
FAttr := FDoc.CreateAttribute('xmlns:xsi');
FAttr.Value := 'http://www.w3.org/2001/XMLSchema-instance';
FSubmission.Attributes.SetNamedItem(FAttr);
FAttr := FDoc.CreateAttribute('xsi:noNamespaceSchemaLocation');
FAttr.Value := 'layout-topologie.xsd';
FSubmission.Attributes.SetNamedItem(FAttr);
FDoc.AppendChild(FSubmission);
Ken White
  • 123,280
  • 14
  • 225
  • 444
S Siddiqui
  • 11
  • 1
  • If you have a new question, then post it as one using the "Ask Question" button at the top of the page, instead of putting it in your answer here. – Ken White Feb 12 '21 at 21:09