Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
399 views
in Technique[技术] by (71.8m points)

delphi - Create XML document using MSXML2_TLB

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>
question from:https://stackoverflow.com/questions/66052043/create-xml-document-using-msxml2-tlb

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...