benpal2476
asked on
Powershell Parse XML and create multiple files
For instnace .....................
<Item>
<value>a</value>
<value>b</value>
</Item>
How do I extract contents of <value> </value> .InnerXml or "a" to a file and create a naming convention. then do the same for <value> </value> .InnerXml or "b" and so on is this possible?
[xml]$xml = (get-content "path.xml")
Foreach ($value in $Item) {
write-host $value.InnerXml
$xml.save("C:\Scripts\new. xml*")
}
This doesent work.
<Item>
<value>a</value>
<value>b</value>
</Item>
How do I extract contents of <value> </value> .InnerXml or "a" to a file and create a naming convention. then do the same for <value> </value> .InnerXml or "b" and so on is this possible?
[xml]$xml = (get-content "path.xml")
Foreach ($value in $Item) {
write-host $value.InnerXml
$xml.save("C:\Scripts\new.
}
This doesent work.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Try this instead:
foreach ($group in $xmlData.benchmark.group)
{
$group.id
$group.title
$group.rule.id
}
Again, you're going to want to try to get a single value at the least to make sure it's working like you planned.
DH
foreach ($group in $xmlData.benchmark.group)
{
$group.id
$group.title
$group.rule.id
}
Again, you're going to want to try to get a single value at the least to make sure it's working like you planned.
DH
Also, if you'd like to have me help a little more, you can post a portion of your XML code (so I can actually run it through and attempt to work with it myself) and I'll see if I can't cook something up.
DH
DH
ASKER
[xml]$xml = (get-content "C:\Users\user\Desktop\xml ")
$xml.SelectNodes("/Item/Al ias") |
Select * | Format-List
I created this it gives me a break down of Alias in the document, I know there are 40 Alias from doing a .count but now i'd like to save the innertext or inner xml of Alias to a seperate file.
Thanks for your time.
$xml.SelectNodes("/Item/Al
Select * | Format-List
I created this it gives me a break down of Alias in the document, I know there are 40 Alias from doing a .count but now i'd like to save the innertext or inner xml of Alias to a seperate file.
Thanks for your time.
Using the following command will help:
$VariablewithStuffInside| get-member
This is the best way to see what kind of properties and method are in that object, just so you can see if you can hit a command to make it work.
I would love your xml file you're actually importing with 40 aliases. This way, I can just take a few minutes to look it over, generate the exact code you need, since you seem to having a difficulty getting the information you need out of this.
DH
$VariablewithStuffInside| get-member
This is the best way to see what kind of properties and method are in that object, just so you can see if you can hit a command to make it work.
I would love your xml file you're actually importing with 40 aliases. This way, I can just take a few minutes to look it over, generate the exact code you need, since you seem to having a difficulty getting the information you need out of this.
DH
ASKER
Foreach ($value in $Item) {
write-host $value.InnerXml
#$xml.save("C:\Scripts\new
#without the "*" it writes to ("C:\Scripts\new.xml")
}
#but I want it to get InnerText for the <value> </value> there are multiple <value> within the xml I would like to get each <value> and output that data to a seperate file.