How can one split the value of an attribute in LINQ (-to-XML)?

I enjoyed getting started doing fun stuff with my adorable bookmarks and LINQ to XML, and was wondering if there was a way to strip a tag attribute in LINQ.

What I had in mind with tag splitting in LINQ generates a rowset for each post element, so the expected result is a generic itemset post

with its attributes as properties, where a tag

property is another rowset, with its elements being each tag.

For those not quite familiar with delicious.com exported xml, here is the basic element structure:

<post
    href="http://stackoverflow.com/"
    hash="e4a42d992025b928a586b8bdc36ad38d"
    description="Stack Overflow"
    tag="code development programming community tips answers reference"
    time="2009-05-22T19:44:09Z"
    extended="Qaru is a programming Q & A site that free."
    meta="e0bf85c9df073cd51cc5528637db5277"
 />

      

Here is the piece of code I am using:

   XDocument delicious = XDocument.Load("all.xml");

  var bookmarks = from posts in delicious.Descendants().Attributes("tag")
                  select (string)posts;

      

Any ideas, suggestions, comments would be really appreciated.

+1


a source to share


3 answers


What is your desired outcome actually? Do you need an array of each value in the "tag" field?

var bookmarks = from posts in delicious.Descendants().Attributes("tag")
                    select ((string)posts).Split(" ");

      



This will give you a list of arrays. It is difficult to say how to accomplish what you want as it is not well stated.

+1


a source


The string class has a Split method.
Is this what you are looking for?



EDIT: string.Join (Environment.NewLine, bookmarks.ToArray ());

+1


a source


What I did was use "set" and assign a value to that variable, and then use set to continue manipulating, so in the end I was able to just use it in my linq query, as I did in a form that is useful to me now .: )

+1


a source







All Articles