Click here to Skip to main content
15,880,392 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
here is the hierarchy that need to create in XML
Example:
MyFile-
XML
<Meta>
 <Image>
   <PNG>
       <URL>
   <PNG>
       <URL>
   <PNG>
       <URL>
   <PNG>
       <URL>
   <PNG>
       <URL>


my current implementation:
[xml] $file = Get-content C:\MyFile.xml
$Parent =$file.Meta
$Child = $file.CreateElement("Image",$Parent.NamespaceURI)
$Parent.AppendChild($Child)
$file.Save("C:\MyFile.xml")

for($j=0; $j -lt 10; $j++){
	$ParentNode =$file.Meta["Image"]
	$ChildNode = $file.CreateElement("PNG",$Parent.NamespaceURI)
	$ParentNode.AppendChild($ChildNode)
	$file.Save("C:\MyFile.xml")
   
	$ParentSubNode =$file.Meta.Image["PNG"]
	$SubChildNode = $metafile.CreateElement("URL",$ParentNode.NamespaceURI)
	$ParentSubNode.AppendChild($SubChildNode)
	$file.Save("C:\MyFile.xml")
    }



The above code is crating the xml as;
XML
<Meta>
 <Image>
   <PNG>
       <URL>
       <URL>
       <URL>
       <URL>
   <PNG>
   <PNG>
   <PNG>


*the node names should not be changed with suffix 0,1,2..etc

Can some one pls help me to solve this issue?
Posted
Updated 10-Sep-11 7:53am
v7

It would appear that all your SubChildNodes are being added to the first PNG node, rather than each one in turn. I have not been able to test this, but perhaps something like:
JavaScript
$ParentNode =$file.Meta["Image"]
for($j=0; $j -lt 10; $j++){
    $ChildNode = $file.CreateElement("PNG",$Parent.NamespaceURI)
    $ParentNode.AppendChild($ChildNode)
    $SubChildNode = $metafile.CreateElement("URL",$ParentNode.NamespaceURI)
    $ChildNode.AppendChild($SubChildNode)
}
$metafile.Save("MyFile.xml")
 
Share this answer
 
Appreciated...Thanks a lot Richard, It works as expected.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900