0

I have a delimited file like this.

Name;ID;Type
ABC;1;Blue
PQR;2;Black

I am trying to make a flat file schema for the above data. But I am not able to find a way to make the XML tags match the headers.

the XML file it is creating is

<Root>
<Root_Child1>Root_Child</Root_Child1>
<Root_Child2>Root_Child</Root_Child2>
<Root_Child3>Root_Child</Root_Child3>
</Root>

What I want is something like this

<Root>
<Name>Root_Child</Name>
<ID>Root_Child</ID>
<Type>Root_Child</Type>
</Root>

I have 55 headers and it is a tedious job to manually change the XSD file . Is there an easier way to achieve this?

Dijkgraaf
  • 9,324
  • 15
  • 34
  • 48
Pratish Nair
  • 91
  • 11
  • No, you just have to update them, the flat file wizard unfortunately doesn't have the smarts to pick up on names in a header row. You could have renamed them in the Flat File Wizard, but that is even more tedious. – Dijkgraaf Sep 27 '17 at 21:22

1 Answers1

-1

I think that this is not possible with only the Flat File Schema. You need to implement a map and create those tags and assign the values.

For example, with this Flat File Schema:

<?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns:b="http://schemas.microsoft.com/BizTalk/2003" xmlns="http://BizTalkMassCopy.FlatFileSchema8" targetNamespace="http://BizTalkMassCopy.FlatFileSchema8" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:annotation>
    <xs:appinfo>
      <schemaEditorExtension:schemaInfo namespaceAlias="b" extensionClass="Microsoft.BizTalk.FlatFileExtension.FlatFileExtension" standardName="Flat File" xmlns:schemaEditorExtension="http://schemas.microsoft.com/BizTalk/2003/SchemaEditorExtensions" />
      <b:schemaInfo standard="Flat File" codepage="65001" default_pad_char=" " pad_char_type="char" count_positions_by_byte="false" parser_optimization="speed" lookahead_depth="3" suppress_empty_nodes="false" generate_empty_nodes="true" allow_early_termination="false" early_terminate_optional_fields="false" allow_message_breakup_of_infix_root="false" compile_parse_tables="false" root_reference="Root" />
    </xs:appinfo>
  </xs:annotation>
  <xs:element name="Root">
    <xs:annotation>
      <xs:appinfo>
        <b:recordInfo structure="delimited" child_delimiter_type="hex" child_delimiter="0xD 0xA" child_order="infix" sequence_number="1" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" />
      </xs:appinfo>
    </xs:annotation>
    <xs:complexType>
      <xs:sequence>
        <xs:annotation>
          <xs:appinfo>
            <groupInfo sequence_number="0" xmlns="http://schemas.microsoft.com/BizTalk/2003" />
          </xs:appinfo>
        </xs:annotation>
        <xs:element name="Headers">
          <xs:annotation>
            <xs:appinfo>
              <b:recordInfo structure="delimited" child_delimiter_type="char" child_delimiter=";" child_order="infix" sequence_number="1" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" />
            </xs:appinfo>
          </xs:annotation>
          <xs:complexType>
            <xs:sequence>
              <xs:annotation>
                <xs:appinfo>
                  <groupInfo sequence_number="0" xmlns="http://schemas.microsoft.com/BizTalk/2003" />
                </xs:appinfo>
              </xs:annotation>
              <xs:element name="Headers_Child1" type="xs:string">
                <xs:annotation>
                  <xs:appinfo>
                    <b:fieldInfo justification="left" sequence_number="1" />
                  </xs:appinfo>
                </xs:annotation>
              </xs:element>
              <xs:element name="Headers_Child2" type="xs:string">
                <xs:annotation>
                  <xs:appinfo>
                    <b:fieldInfo justification="left" sequence_number="2" />
                  </xs:appinfo>
                </xs:annotation>
              </xs:element>
              <xs:element name="Headers_Child3" type="xs:string">
                <xs:annotation>
                  <xs:appinfo>
                    <b:fieldInfo justification="left" sequence_number="3" />
                  </xs:appinfo>
                </xs:annotation>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
        <xs:element maxOccurs="unbounded" name="Item">
          <xs:annotation>
            <xs:appinfo>
              <b:recordInfo structure="delimited" child_delimiter_type="char" child_delimiter=";" child_order="infix" sequence_number="2" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" />
            </xs:appinfo>
          </xs:annotation>
          <xs:complexType>
            <xs:sequence>
              <xs:annotation>
                <xs:appinfo>
                  <groupInfo sequence_number="0" xmlns="http://schemas.microsoft.com/BizTalk/2003" />
                </xs:appinfo>
              </xs:annotation>
              <xs:element name="Item_Child1" type="xs:string">
                <xs:annotation>
                  <xs:appinfo>
                    <b:fieldInfo justification="left" sequence_number="1" />
                  </xs:appinfo>
                </xs:annotation>
              </xs:element>
              <xs:element name="Item_Child2" type="xs:string">
                <xs:annotation>
                  <xs:appinfo>
                    <b:fieldInfo justification="left" sequence_number="2" />
                  </xs:appinfo>
                </xs:annotation>
              </xs:element>
              <xs:element name="Item_Child3" type="xs:string">
                <xs:annotation>
                  <xs:appinfo>
                    <b:fieldInfo justification="left" sequence_number="3" />
                  </xs:appinfo>
                </xs:annotation>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

And then you implement a Map with this Custom XSLT:

<?xml version="1.0" encoding="UTF-16"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:var="http://schemas.microsoft.com/BizTalk/2003/var" exclude-result-prefixes="msxsl var s0" version="1.0" xmlns:s0="http://BizTalkMassCopy.FlatFileSchema8" xmlns:ns0="http://BizTalkMassCopy.Schema2">
  <xsl:output omit-xml-declaration="yes" method="xml" version="1.0" />
  <xsl:template match="/">
    <xsl:apply-templates select="/s0:Root" />
  </xsl:template>
  <xsl:template match="/s0:Root">
    <xsl:variable name="var:v1" select="Headers/Headers_Child1/text()" />
    <xsl:variable name="var:v2" select="Headers/Headers_Child2/text()" />
    <xsl:variable name="var:v3" select="Headers/Headers_Child3/text()" />

    <ns0:Root>
      <xsl:for-each select="Item">
        <xsl:element name="Items">
          <xsl:element name="{$var:v1}">
            <xsl:value-of select="Item_Child1" />
          </xsl:element>
          <xsl:element name="{$var:v2}">
            <xsl:value-of select="Item_Child2" />
          </xsl:element>
          <xsl:element name="{$var:v3}">
            <xsl:value-of select="Item_Child3" />
          </xsl:element>
        </xsl:element>
      </xsl:for-each>
    </ns0:Root>
  </xsl:template>
</xsl:stylesheet>
felixmondelo
  • 1,224
  • 1
  • 10
  • 16
  • You can rename the elements in a flat file schema with no issue and it is actually good practice to do so. – Dijkgraaf Sep 28 '17 at 02:52
  • The question was if it is possible to do automatically, because he has a lot of fields and in my response I gave a solution using maps to generate the desired tags. – felixmondelo Sep 28 '17 at 09:16
  • Is the output a XSD file though? If your XSLT can take the XSD file and rename the elements, plus you remove or amend your first sentence (which is not correct), then your answer will be correct. – Dijkgraaf Sep 28 '17 at 17:43