Script to reformat XML file
Posted
by JonS
on Stack Overflow
See other posts from Stack Overflow
or by JonS
Published on 2010-04-21T16:40:29Z
Indexed on
2010/04/21
16:43 UTC
Read the original article
Hit count: 327
Hello all,
I am trying to change an XML file from one format to another and have no clue as to how to write a script for it. Can someone help, please?
The source file looks like this:
<Record>
<FieldValue fieldName="rapportage_nihil" fieldValue="false" fieldValueIsNull="false" fieldValueNatural="false"/>
<FieldValue fieldName="periode" fieldValue="2009-23-31" fieldValueIsNull="false" fieldValueNatural="2009-10-31 00:23:23"/>
<FieldValue fieldName="formulierid" fieldValue="9001HK1V10" fieldValueIsNull="false" fieldValueNatural="9001HK1V10"/>
<FieldValue fieldName="versie" fieldValue="1" fieldValueIsNull="false" fieldValueNatural="1"/>
<FieldValue fieldName="frequentie" fieldValue="M" fieldValueIsNull="false" fieldValueNatural="M"/>
<FieldValue fieldName="variant_type" fieldValue="Landen" fieldValueIsNull="false" fieldValueNatural="Landen"/>
<FieldValue fieldName="value" fieldValue="5F" fieldValueIsNull="false" fieldValueNatural="5F"/>
<FieldValue fieldName="post_value" fieldValue="0.00" fieldValueIsNull="false" fieldValueNatural="1.037E-4"/>
<FieldValue fieldName="cube" fieldValue="c01" fieldValueIsNull="false" fieldValueNatural="c01"/>
<FieldValue fieldName="rij" fieldValue="r_24_100_1_000_0" fieldValueIsNull="false" fieldValueNatural="r_24_100_1_000_0"/>
<FieldValue fieldName="kolom" fieldValue="c_2250_SPU" fieldValueIsNull="false" fieldValueNatural="c_2250_SPU"/>
</Record>
<Record>
<FieldValue fieldName="rapportage_nihil" fieldValue="false" fieldValueIsNull="false" fieldValueNatural="false"/>
<FieldValue fieldName="periode" fieldValue="2009-23-31" fieldValueIsNull="false" fieldValueNatural="2009-10-31 00:23:23"/>
<FieldValue fieldName="formulierid" fieldValue="9001HK1V10" fieldValueIsNull="false" fieldValueNatural="9001HK1V10"/>
<FieldValue fieldName="versie" fieldValue="1" fieldValueIsNull="false" fieldValueNatural="1"/>
<FieldValue fieldName="frequentie" fieldValue="M" fieldValueIsNull="false" fieldValueNatural="M"/>
<FieldValue fieldName="variant_type" fieldValue="Landen" fieldValueIsNull="false" fieldValueNatural="Landen"/>
<FieldValue fieldName="value" fieldValue="5F" fieldValueIsNull="false" fieldValueNatural="5F"/>
<FieldValue fieldName="post_value" fieldValue="0.00" fieldValueIsNull="false" fieldValueNatural="1.037E-4"/>
<FieldValue fieldName="cube" fieldValue="c01" fieldValueIsNull="false" fieldValueNatural="c01"/>
<FieldValue fieldName="rij" fieldValue="r_24_108_0_000_0" fieldValueIsNull="false" fieldValueNatural="r_24_108_0_000_0"/>
<FieldValue fieldName="kolom" fieldValue="c_2250_SPU" fieldValueIsNull="false" fieldValueNatural="c_2250_SPU"/>
</Record>
<Record>
<FieldValue fieldName="rapportage_nihil" fieldValue="false" fieldValueIsNull="false" fieldValueNatural="false"/>
<FieldValue fieldName="periode" fieldValue="2009-23-31" fieldValueIsNull="false" fieldValueNatural="2009-10-31 00:23:23"/>
<FieldValue fieldName="formulierid" fieldValue="9001HK1V10" fieldValueIsNull="false" fieldValueNatural="9001HK1V10"/>
<FieldValue fieldName="versie" fieldValue="1" fieldValueIsNull="false" fieldValueNatural="1"/>
<FieldValue fieldName="frequentie" fieldValue="M" fieldValueIsNull="false" fieldValueNatural="M"/>
<FieldValue fieldName="variant_type" fieldValue="Landen" fieldValueIsNull="false" fieldValueNatural="Landen"/>
<FieldValue fieldName="value" fieldValue="5F" fieldValueIsNull="false" fieldValueNatural="5F"/>
<FieldValue fieldName="post_value" fieldValue="0.00" fieldValueIsNull="false" fieldValueNatural="1.6049E-4"/>
<FieldValue fieldName="cube" fieldValue="c01" fieldValueIsNull="false" fieldValueNatural="c01"/>
<FieldValue fieldName="rij" fieldValue="r_06_000_1_010_0" fieldValueIsNull="false" fieldValueNatural="r_06_000_1_010_0"/>
<FieldValue fieldName="kolom" fieldValue="c_2250_SPU" fieldValueIsNull="false" fieldValueNatural="c_2250_SPU"/>
</Record>
This is the format that I need as a result:
<bestand registratienummer="123">
<rapportage nihil="false" periode="2009-23-31" formulierid="9001HK1V10" versie="1" frequentie="M">
<variant type="Landen" value="5F" />
<post value="0.00" cube="c01" rij="r_24_100_1_000_0" kolom="c_2250_SPU" />
</rapportage>
<rapportage nihil="false" periode="2009-23-31" formulierid="9001HK1V10" versie="1" frequentie="M">
<variant type="Landen" value="5F" />
<post value="0.00" cube="c01" rij="r_24_108_0_000_0" kolom="c_2250_SPU" />
</rapportage>
<rapportage nihil="false" periode="2009-23-31" formulierid="9001HK1V10" versie="1" frequentie="M">
<variant type="Landen" value="5F" />
<post value="0.00" cube="c01" rij="r_06_000_1_010_0" kolom="c_2250_SPU" />
</rapportage>
</bestand>
Thanks very much!
© Stack Overflow or respective owner