none
Extract a subset from the main XML.

    Question

  • Hello,

    I have the following XML that holds a list of locales, each one of which has a few properties:

    (excerpt from full table)

    <Locales>
    	...
    	<Locale ID="en" Property1="xx" Property2="xx" ...>English</Locale>
    	<Locale ID="en-GB" Property1="xx" Property2="xx" ...>English (United Kingdom)</Locale>
    	<Locale ID="en-US" Property1="xx" Property2="xx" ...>English (United States)</Locale>
    	...
    	<Locale ID="fr" Property1="yy" Property2="yy" ...>French</Locale>
    	<Locale ID="fr-BE" Property1="yy" Property2="yy" ...>French (Belgium)</Locale>
    	...
    	<Locale ID="it" Property1="zz" Property2="zz" ...>Italian</Locale>
    	<Locale ID="it-CH" Property1="zz" Property2="zz" ...>Italian (Switzerland)</Locale>
    	...
    </Locales>

    I currently use the following syntax to retrieve the value of the rows that match a given property:
    (VB.Net)

    Return (From el In xml.Elements
    	Where el.@Property1 IsNot Nothing AndAlso el.@Property1 = "xx"
    	Select el.Value
    	Order By Value).ToList()			
    

    I would rather like to obtain an XML which actually is a subset of the main document, but lists only the rows that match the search criteria.

    For example:

    <Locales>
    	<Locale ID="en" Property1="xx" Property2="xx" ...>English</Locale>
    	<Locale ID="en-GB" Property1="xx" Property2="xx" ...>English (United Kingdom)</Locale>
    	<Locale ID="en-US" Property1="xx" Property2="xx" ...>English (United States)</Locale>
    </Locales>
    

    Is there any easy way to accomplish this?

    Thank you for your help.
    M.

    Wednesday, October 09, 2013 8:38 AM

Answers