This project is read-only.

How to read child node in an Xml file?

Sep 18, 2013 at 10:11 AM

I would like to know if it's possible to read a child by passing from the parent.


I read the node "Server" with:
<MSBuild.ExtensionPack.Xml.XmlFile TaskAction="ReadElements" File="server.config" XPath="//configuration/Server">
            <Output TaskParameter="Elements" ItemName="Server" />
And I would like to display all child nodes with something like this:
<Message Text="%(Server.RootDirectory) - %(Server.IP)"/>
Any ideas?
Sep 18, 2013 at 11:33 AM

The docs have

ReadElements (Required: File, XPath Optional: Namespaces Output: Elements). Attributes are added as metadata

So if those sub elements were attributes you'd get what you are after.

I guess you think it would be useful to have similar functionality to read first child level elements.... I'll add a WI to provide this and see what can be done.

Sep 18, 2013 at 11:48 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Sep 18, 2013 at 11:55 AM
If you try the latest code from Main (.net 4) you can use the new ReadChildrenToMetadata property to do what you need. Remember to skip signing verification if you compile the code yourself...

Marked as answer by mikeFourie on 10/9/2013 at 3:03 PM
Sep 18, 2013 at 1:05 PM
Thank you!

It's perfect!