Menu

Character replacement inflat2XML conversion

Help
2013-06-12
2013-06-13
  • aitor etxebarria gaztañaga

    Hi everyone,

    I have a problem when converting a flat file to XML. When I found a control character in the flat file, I want to find the way to replace that special character with any other normal character, for example "*". I have tried using the function "escapeSubstitutions", but without any satisfactory result. I have also tried with the "findAndReplace" function, but nothing. 
    The problem is that when the conversion from flat to XMl is done, in the generated XML file I can find characters that make impossible to process that XML, because the character is not admitted. 
    What can I do to solve this problem?
    

    Thank you very much

     
  • aitor etxebarria gaztañaga

    A little more information about my execution:

    This is an example of a flat file I want to convert to XML(prueba):

    0t
    

    This is my resources file (prueba.xml):

    <sx:resources xmlns:sx="http://www.servingxml.com/core"
                  xmlns:msv="http://www.servingxml.com/extensions/msv">
    
      <sx:service id="Factura">
        <sx:serialize>
          <sx:transform>
            <sx:content ref="Factura"/>
             <sx:removeEmptyElements elements="*"/>
                     <sx:escapeSubstitutions character='t' escapeCharacter="a"/>
         <sx:findAndReplace searchFor="t" replaceWith ="a">
            <sx:toString value="{bla}"/>
          </sx:findAndReplace>
    
         </sx:transform>
        </sx:serialize>
      </sx:service>
    
      <sx:recordContent id="Factura">
        <sx:flatFileReader>
          <sx:flatFile ref="flatFile"/>
        </sx:flatFileReader>
             <sx:composeRecord recordType="composite" repeatingGroup="detail"
                                                startTest="sx:current//TIPO-REG='0'">
          </sx:composeRecord>
        <sx:recordMapping ref="tradesToXmlMapping"/>
      </sx:recordContent>
    
    
    
      <sx:flatFile id="flatFile">
        <sx:flatFileBody>
          <sx:flatRecordType name="Registro">
            <sx:positionalField name="TIPO-REG" width="1"/>
            <sx:positionalField name="bla" width="1"/>
    
    
          </sx:flatRecordType>
        </sx:flatFileBody>
      </sx:flatFile>
    
      <sx:recordMapping id="tradesToXmlMapping">
        <root>
         <sx:onRecord recordType="composite">
          <PAGINA>
          <sx:subrecordMapping repeatingGroup="detail">
          <sx:onRecord>
            <REGISTRO>
              <sx:fieldElementMap field="TIPO-REG" element="TIPO-REG"/>
               <sx:fieldElementMap field="bla" element="bla"/>
            </REGISTRO>
             </sx:onRecord>
          </sx:subrecordMapping>
            </PAGINA>
          </sx:onRecord>
        </root>
      </sx:recordMapping>
    </sx:resources>
    

    As you can see, I have included in the example both functions I have used to resolve this problema: escapeSubstitutions and findAndReplace

    This is the way i call the execution:

    servingXML -r prueba.xml -i prueba -o output.xml Factura
    

    And the resultant XML file is this(output.xml):

    <?xml version="1.0" encoding="UTF-8"?>
    <root>
       <PAGINA>
          <REGISTRO>
             <TIPO-REG>0</TIPO-REG>
             <bla>t</bla>
          </REGISTRO>
       </PAGINA>
    </root> 
    

    If for example, every time that comes a "t" in the flat file, I want to representate it on the XML file as an "a", what should I do?

    Thank you very much

     

    Last edit: aitor etxebarria gaztañaga 2013-06-12
  • aitor etxebarria gaztañaga

    Hi again to everone,

    I rewrite my messagge to see if anyone has find a solution to my problem. I would be very grateful if somebody could help me. I will rewrite all my execution so you an see everything on the mail list, because I think my first messagge didn't reach to you in the right format.

    This is an example of a flat file I want to convert to XML(prueba):

    0t
    

    This is my resources file (prueba.xml):

    <sx:resources xmlns:sx="http://www.servingxml.com/core"
                  xmlns:msv="http://www.servingxml.com/extensions/msv">
    
      <sx:service id="Factura">
        <sx:serialize>
          <sx:transform>
            <sx:content ref="Factura"/>
             <sx:removeEmptyElements elements="*"/>
                     <sx:escapeSubstitutions character='t' escapeCharacter="a"/>
         <sx:findAndReplace searchFor="t" replaceWith ="a">
            <sx:toString value="{bla}"/>
          </sx:findAndReplace>
    
         </sx:transform>
        </sx:serialize>
      </sx:service>
    
      <sx:recordContent id="Factura">
        <sx:flatFileReader>
          <sx:flatFile ref="flatFile"/>
        </sx:flatFileReader>
             <sx:composeRecord recordType="composite" repeatingGroup="detail"
                                                startTest="sx:current//TIPO-REG='0'">
          </sx:composeRecord>
        <sx:recordMapping ref="tradesToXmlMapping"/>
      </sx:recordContent>
    
      <sx:flatFile id="flatFile">
        <sx:flatFileBody>
          <sx:flatRecordType name="Registro">
            <sx:positionalField name="TIPO-REG" width="1"/>
            <sx:positionalField name="bla" width="1"/>
    
          </sx:flatRecordType>
        </sx:flatFileBody>
      </sx:flatFile>
    
      <sx:recordMapping id="tradesToXmlMapping">
        <root>
         <sx:onRecord recordType="composite">
          <PAGINA>
          <sx:subrecordMapping repeatingGroup="detail">
          <sx:onRecord>
            <REGISTRO>
              <sx:fieldElementMap field="TIPO-REG" element="TIPO-REG"/>
               <sx:fieldElementMap field="bla" element="bla"/>
            </REGISTRO>
             </sx:onRecord>
          </sx:subrecordMapping>
            </PAGINA>
          </sx:onRecord>
        </root>
      </sx:recordMapping>
    </sx:resources>
    

    As you can see, I have included in the example both functions I have used to resolve this problema: escapeSubstitutions and findAndReplace
    This is the way i call the execution:

    servingXML -r prueba.xml -i prueba -o output.xml Factura
    

    And the resultant XML file is this(output.xml):

    <?xml version="1.0" encoding="UTF-8"?>
    <root>
       <PAGINA>
          <REGISTRO>
             <TIPO-REG>0</TIPO-REG>
             <bla>t</bla>
          </REGISTRO>
       </PAGINA>
    </root>
    

    If for example, every time that comes a "t" in the flat file, I want to representate it on the XML file as an "a", what should I do?
    Thank you very much again, I'm so sorry of being so insistent.

     

    Last edit: aitor etxebarria gaztañaga 2013-06-13

Log in to post a comment.

MongoDB Logo MongoDB