How to transform xml to another format

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • perlprogrammer
    New Member
    • Nov 2008
    • 4

    How to transform xml to another format

    Hi,

    i would like to transform xml to another format (in doing so i loose the orignal xml format). Again i would like transform to the original XML format.

    is there a way to save the xml format in some way so that u can change back to original.

    Regards
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    Originally posted by perlprogrammer
    i would like to transform xml to another format [...]. Again i would like transform to the original XML format.
    why do you want to do that (it's not really clear to me)? you probably have to write the "inverse" transformation file of the original one.
    I think it's better to make the transformation, and if you want to apply changes to the original file, write a transformation (filter) that works on the original file.

    Originally posted by perlprogrammer
    is there a way to save the xml format in some way so that u can change back to original.
    you save an "XML format" as a validation file (DTD, XML Schema, RelaxNG) but those are meant to check if an XML document conforms to that "format" or not.

    regards

    Comment

    • perlprogrammer
      New Member
      • Nov 2008
      • 4

      #3
      i have two systems which need the file in two different formats.
      sat i have xml1
      [code=-xml]
      <root>
      <data1> hi</data1>
      <sub> stuff<sub>
      </root>[/code]


      i convert it to xml2 for second system which might change the value
      [code=xml]
      <root>
      <data> hi</data>
      </root>
      [/code]

      when passing back this xml2 to system 1 i need it in the xml1 format.

      So if i have xslt or some custom script which convertes to format 2..is there a way to convert back to format 1....(by saying dom defination or anything?

      i am not sure how to achieve this, that is why asked here?
      Last edited by Frinavale; Dec 9 '08, 05:18 PM. Reason: added code tags

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        so you want that the xml from second system updates your original xml?

        Comment

        • perlprogrammer
          New Member
          • Nov 2008
          • 4

          #5
          that is correct..that is exactly what i want...since the xml formats are different....no t sure how to hide the information about the xml format 1 in second one and use that information when transforming back....

          Comment

          • Dormilich
            Recognized Expert Expert
            • Aug 2008
            • 8694

            #6
            I'd still do an update of xml1 with xml2. for that to work you need to include xml2 via the document()-function. works like
            Code:
            <xsl:variable name="returned" select="document('xml2.xml', /root)"/>
            // some copy-xslt
            <xsl:template match="data">
              <data><xsl:value-of select="$returned/data[position() = current()/position()]"/></data>
            </xsl:template>
            note: this is a sketch, the actual implementation depends on your xml files.

            regards

            PS: there should be some threads around that deal with similar topics

            Comment

            • perlprogrammer
              New Member
              • Nov 2008
              • 4

              #7
              Thanks for your reply

              But still i cannot see how can i achieve the following
              when i transform xml format 1 to xml format 2 so that second system would except it..change the value somehow..give back the xml format 2 to system1 who does not know anything for how to change to fomrat 1 as it does not have the data lost in first transformation.

              If i do what you suggested how would i do know once the format 2 is returned back by system 2 it should be mapped to some xml in fomat 1..Hope there is better way to do it which would address my issue.

              Comment

              • Dormilich
                Recognized Expert Expert
                • Aug 2008
                • 8694

                #8
                Originally posted by perlprogrammer
                If i do what you suggested how would i do know once the format 2 is returned back by system 2 it should be mapped to some xml in fomat 1..Hope there is better way to do it which would address my issue.
                if you do not cross-reference your data (this can be an ID type attribute or just a preserve order/count), you will never get them updated, independent of the method you use.

                if you only want to format xml2 back, no matter what changes may apply and what not, you should write the inverse transformation to xml1→xml2.

                regards

                Comment

                • jkmyoung
                  Recognized Expert Top Contributor
                  • Mar 2006
                  • 2057

                  #9
                  Maybe use namespaces?
                  XML namespace - Wikipedia, the free encyclopedia
                  Namespaces in XML 1.0 (Second Edition)
                  The 2nd service would have to be able to ignore xml from another namespace.

                  Comment

                  Working...