문제

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 will 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?

도움이 되었습니까?

해결책 2

Finally, with the help of Mike Fourie (Solution), there is a solution.

You need to download the latest source code, compile the .sln and copy binaries to your folder c:\Program Files\Msbuild\ExtensionPack to use the property "ReadChildrenToMetadata" like that:

<configuration>

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

</configuration>

ReadElements:

<MSBuild.ExtensionPack.Xml.XmlFile TaskAction="ReadElements" ReadChildrenToMetadata="true" File="Config\ftp.config" XPath="//configuration/Server">
            <Output TaskParameter="Elements" ItemName="Server" />
</MSBuild.ExtensionPack.Xml.XmlFile>

<Message Text="%(Server.RootDirectory) - %(Server.IP)"/>

And you will get:

Temp - 192.168.10.10

다른 팁

<?xml version="1.0" encoding="utf-8"?>
<Project  ToolsVersion="4.0"  xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="AllTargetsWrapped">


    <Target Name="AllTargetsWrapped">
        <CallTarget Targets="ReadXmlPeekValue" />
        <CallTarget Targets="ParseIndividualXmls" />
    </Target>   


    <Target Name="ReadXmlPeekValue">
        <!-- you do not need a namespace for this example, but I left it in for future reference -->
        <XmlPeek Namespaces="&lt;Namespace Prefix='peanutNamespace' Uri='http://schemas.microsoft.com/developer/msbuild/2003'/&gt;"
             XmlInputPath=".\Parameters.xml" 
             Query="/configuration/Server">
            <Output TaskParameter="Result" ItemName="Peeked" />
        </XmlPeek>

        <Message Text="@(Peeked)"/>

    </Target>   


    <Target Name="ParseIndividualXmls"  Outputs="%(Peeked.Identity)">

        <!-- See http://sstjean.blogspot.com/2006/09/how-to-get-msbuild-to-run-complete.html  -->

        <PropertyGroup>
            <MyXmlSnipplet>%(Peeked.Identity)</MyXmlSnipplet>
        </PropertyGroup>


        <!--
        <Message Text=" MyXmlSnipplet = $(MyXmlSnipplet)  "/>
        -->

        <XmlPeek Namespaces="&lt;Namespace Prefix='peanutNamespace' Uri='http://schemas.microsoft.com/developer/msbuild/2003'/&gt;"
             XmlContent="$(MyXmlSnipplet)" 
             Query="/Server/RootDirectory[1]/text()">
            <Output TaskParameter="Result" PropertyName="MyRootDirectory" />
        </XmlPeek>

        <Message Text="  MyRootDirectory = $(MyRootDirectory) "/>


        <XmlPeek Namespaces="&lt;Namespace Prefix='peanutNamespace' Uri='http://schemas.microsoft.com/developer/msbuild/2003'/&gt;"
             XmlContent="$(MyXmlSnipplet)" 
             Query="/Server/IP[1]/text()">
            <Output TaskParameter="Result" PropertyName="MyIP" />
        </XmlPeek>

        <Message Text="  MyIP = $(MyIP) "/>     

    </Target>



    <!--
                <configuration>

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



                    <Server>
                        <RootDirectory>Poopty</RootDirectory>
                        <IP>10.0.1.444</IP>
                        <Port>333</Port>
                        <UserName>Scott</UserName>
                        <UserPassword>Tiger</UserPassword>       
                    </Server>


                </configuration>

-->


</Project>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top