How to create XML from data

Hi, Can anyone send me a knime example that can do this:

  1. data read , a select query from table and generate some result–done.
  2. put in XML, this XML need to be exact format that my customer need. So basically, the customer send me the XML format, and I need to fill in with my order data .
    Can Knime do that?
    I tried with data reader–Table to Json–Json to XML–XML writer. It does generated XML file, but not in the format the customer need .

Is there a way in Knime that can read the customer xml, then put value in, then generate same format XML?

thanks.

1 Like

Hi @fanrf,

Will you be able to provide an example workflow of your partial solution? A toy dataset will do fine.

Can you also share the structure/formal of the XML that you want to populate with the data? This is important to answer your question.

Best,
Temesgen

1 Like

Thanks for the response.
So far I didn’t make too much progress. I can only find column to XML in knime and that didn’t help much.
The whole purpose is read data from Sql serve table, like a sales invoice infor, and fill in the XML like below.

<?xml version="1.0" encoding="UTF-8"?>
<From>

  <Credential domain="Dom1">

    <Identity>Kyle</Identity>

  </Credential>

</From>

<To>

  <Credential domain="Dom2">

    <Identity>Coupa</Identity>

  </Credential>

</To>

<Sender>

  <Credential domain="Dom3">

    <Identity>Test</Identity>

    <SharedSecret>Secret</SharedSecret>

  </Credential>

  <UserAgent>Your Very Own Agent 1.23</UserAgent>

</Sender>
<InvoiceDetailRequest>

  <InvoiceDetailRequestHeader invoiceID="CD24706_882015_8" purpose="standard" operation="new" invoiceDate="2015-04-30T11:45:51-07:00">

    <InvoiceDetailHeaderIndicator />

    <InvoiceDetailLineIndicator isAccountingInLine="yes" />

    <InvoicePartner>

      <Contact role="remitTo" addressID="RTCode">

        <Name xml:lang="en">RTName</Name>

      </Contact>

    </InvoicePartner>

    <InvoicePartner>

      <Contact role="billTo">

        <Name xml:lang="en">xxx yyy</Name>

        <PostalAddress name="default">

          <Street>Line1</Street>

          <Street>Line2</Street>

          <City>City</City>

          <State>State</State>

          <PostalCode>151515</PostalCode>

          <Country isoCountryCode="BE">1</Country>

        </PostalAddress>

        <Email name="default">harinni.coupa01@gmail.com</Email>

        <Phone name="work">

          <TelephoneNumber>

            <CountryCode isoCountryCode="BE">Belgium</CountryCode>

            <AreaOrCityCode>745</AreaOrCityCode>

            <Number>+1 (987) 654-3210</Number>

          </TelephoneNumber>

        </Phone>

      </Contact>

    </InvoicePartner>

    <PaymentTerm payInNumberOfDays="30" />

  </InvoiceDetailRequestHeader>

  <InvoiceDetailOrder>

    <InvoiceDetailOrderInfo>

      <MasterAgreementReference>

        <!-- payloadID is the Contract number -->

        <DocumentReference payloadID="441" />

      </MasterAgreementReference>

    </InvoiceDetailOrderInfo>

    <!-- First invoice quantity line. -->

    <InvoiceDetailItem invoiceLineNumber="1" quantity="1">
   <UnitOfMeasure>EA</UnitOfMeasure>

      <UnitPrice>

        <Money currency="USD">100</Money>

      </UnitPrice>

      <InvoiceDetailItemReference lineNumber="1">

        <Description xml:lang="en">Item01</Description>

      </InvoiceDetailItemReference>

      <SubtotalAmount>

        <Money currency="USD">100</Money>

      </SubtotalAmount>

    </InvoiceDetailItem>

  </InvoiceDetailOrder>

  <InvoiceDetailSummary>

    <SubtotalAmount>

      <Money currency="USD">100</Money>

    </SubtotalAmount>

    <Tax>

      <Money currency="USD" alternateAmount="10" alternateCurrency="EUR">8</Money>

      <Description xml:lang="en">total tax</Description>

      <TaxDetail purpose="tax" category="Standard Rate" percentageRate="20" taxPointDate="2014-06-30T11:45:51-07:00">

        <TaxableAmount>

          <Money currency="USD">100</Money>

        </TaxableAmount>

        <TaxAmount>

          <Money currency="USD">20</Money>

        </TaxAmount>

        <TaxLocation xml:lang="en">CA</TaxLocation>

      </TaxDetail>

    </Tax>

    <NetAmount>

      <Money currency="USD" />

    </NetAmount>

  </InvoiceDetailSummary>

</InvoiceDetailRequest>
1 Like

Yes the Column To XML node is a good starting point. There is also the XML Row Combiner Node which allows you to do combine XML elements under a parent element.

Have a look at this example workflow from the KNIME Hub. It shows how create XML elements, combine them and also insert attributes. This should cover the basics.

Hope this helps!
Temesgen

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.