I have a file like this
<?xml version="1.0"?>
<DD:node1 xmlns:DD="www.dd.com/dd"
DD:attr1="1"
DD:attr2="2"
<DD:Props
DD:Name="anyName">123</DD:Props>
<DD:node2>
<DD:node21>
DD:attr1="1"
DD:attr2="2"
</DD:node21>
<DD:node22>
DD:attr1="1"
DD:attr2="2"
</DD:node22>
</DD:node2>
<DD:node3>
<DD:node31>
DD:attr1="1"
DD:attr2="2"
</DD:node31>
<DD:node32>
DD:attr1="1"
DD:attr2="2"
</DD:node32>
</DD:node3>
</DD:node1>
What is the best way to split this file to few as every node to another file, but with some rules:
- Some files should contain only attributes of node and its name, without child nodes
- Some files should contain child nodes entirely (which nodes in which files, entirely or not I will describe in my code)
- Files should be write to different folders, dependence of some attributes values or nodes names
- General condition: to save tags "as is" in original file - without xmlns section in every file, but with prefix of namespace. I know that in context of xml this will be a bad files, but it does not matter in my case.
Expected result:
First file
<?xml version="1.0"?>
<DD:node1 xmlns:DD="www.dd.com/dd"
DD:attr1="1"
DD:attr2="2"
</DD:node1>
Second file
<DD:Props
DD:Name="anyName">123</DD:Props>
third
<DD:node21>
DD:attr1="1"
DD:attr2="2"
</DD:node21>
and no file with
<DD:node2> </DD:node2>
only subchild of node2 (it does not metter node2 or node3 in this case, this is just an example)
General condition: to save tags "as is" in original file - without xmlns section, but with prefix of namespace.
as if you work not with xml, but with the simple text file and splitting it
I dont ask how to write files in folders, I'm looking for how to split with format saving