How to read child node in an Xml file?

Sep 18, 2013 at 9:11 AM
Hi,

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

    <Server>
        <RootDirectory>Temp</RootDirectory>
        <IP>192.168.10.10</IP>
        <Port>350</Port>
        <UserName>USERNAME</UserName>
        <UserPassword>PASSWORD</UserPassword>       
    </Server>

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

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.

Mike
Coordinator
Sep 18, 2013 at 10:48 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Coordinator
Sep 18, 2013 at 10: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... https://msbuildextensionpack.codeplex.com/wikipage?title=DevelopingLatest&referringTitle=Documentation

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

It's perfect!