469,280 Members | 1,855 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,280 developers. It's quick & easy.

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
Nov 28 '08 #1
8 4919
Dormilich
8,651 Expert Mod 8TB
@perlprogrammer
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.

@perlprogrammer
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
Nov 28 '08 #2
i have two systems which need the file in two different formats.
sat i have xml1
Expand|Select|Wrap|Line Numbers
  1. <root>
  2.     <data1> hi</data1>
  3.     <sub> stuff<sub>
  4. </root>

i convert it to xml2 for second system which might change the value
Expand|Select|Wrap|Line Numbers
  1. <root>
  2. <data> hi</data>
  3. </root>
  4.  
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?
Nov 28 '08 #3
Dormilich
8,651 Expert Mod 8TB
so you want that the xml from second system updates your original xml?
Nov 28 '08 #4
that is correct..that is exactly what i want...since the xml formats are different....not sure how to hide the information about the xml format 1 in second one and use that information when transforming back....
Nov 28 '08 #5
Dormilich
8,651 Expert Mod 8TB
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
Expand|Select|Wrap|Line Numbers
  1. <xsl:variable name="returned" select="document('xml2.xml', /root)"/>
  2. // some copy-xslt
  3. <xsl:template match="data">
  4.   <data><xsl:value-of select="$returned/data[position() = current()/position()]"/></data>
  5. </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
Nov 28 '08 #6
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.
Nov 28 '08 #7
Dormilich
8,651 Expert Mod 8TB
@perlprogrammer
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
Nov 28 '08 #8
jkmyoung
2,057 Expert 2GB
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.
Dec 1 '08 #9

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by Luther Baker | last post: by
6 posts views Thread by Stephen Cook | last post: by
7 posts views Thread by Doug Heeren | last post: by
4 posts views Thread by Cedric | last post: by
1 post views Thread by adi | last post: by
2 posts views Thread by =?Utf-8?B?S2lt?= | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.