Hi
I am new to XML so clarity in your explanation will be greatly appreciated.
I have the response from an XML soap message that has in it many occurrences of the parent node named "<establishment>"
The XML document may contain one or more occurrences of the child nodes named "<room>" under the parent node named "<establishment>".
I need a conditional "if then" statement that tests to see if there are more than one child "<room>" node under the parent node "<establishment>". If there is only one found then the next"<establishment node needs to be tested and so on. If the test finds that there are more than one occurrence of the "<room>" node then a new parent node named "<establishment>" should be created and the content of one occurrence of the "<room>" node from the original "<establishment>" node should be inserted into the newly created "<establishment>" node along with all of the other nodes that were in the original "<establishment>" node. This should happen for each occurrence of "<room>" node that is found.
I need the code that will take this XML document below and transform it to the XML document list at the end o this posting:
<establishment>
<room>
<code>DBL.SU</code>
<description>DOUBLE/ TWIN SUPERIOR</description>
<availability>999</availab
ility>
<price>
<occupancy>
<adults>2</adults>
<children>0</children>
<rooms>1</rooms>
</occupancy>
<board_type>
<code>HD</code>
<description>BED AND BREAKFAST</description>
</board_type>
<amount>386.54</amount>
</price>
</room>
<room>
<code>DBL.SU</code>
<description>DOUBLE/ SUITE</description>
<availability>999</availab
ility>
<price>
<occupancy>
<adults>2</adults>
<children>0</children>
<rooms>1</rooms>
</occupancy>
<board_type>
<code>HD</code>
<description>BED AND BREAKFAST</description>
</board_type>
<amount>346.21</amount>
</price>
</room>
and transform it into this XML format;
<establishment>
<room>
<code>DBL.SU</code>
<description>DOUBLE/ TWIN SUPERIOR</description>
<availability>999</availab
ility>
<price>
<occupancy>
<adults>2</adults>
<children>0</children>
<rooms>1</rooms>
</occupancy>
<board_type>
<code>HD</code>
<description>BED AND BREAKFAST</description>
</board_type>
<amount>386.54</amount>
</price>
</room>
</establishment>
<establishment>
<room>
<code>DBL.SU</code>
<description>DOUBLE/ TWIN SUPERIOR</description>
<availability>999</availab
ility>
<room>
<code>DBL.SU</code>
<description>DOUBLE/ SUITE</description>
<availability>999</availab
ility>
<price>
<occupancy>
<adults>2</adults>
<children>0</children>
<rooms>1</rooms>
</occupancy>
<board_type>
<code>HD</code>
<description>BED AND BREAKFAST</description>
</board_type>
<amount>346.21</amount>
</price>
</room>
</establishment>
Thanks in advance
Wil
Start Free Trial