Solved

LINQ join together

Posted on 2014-07-25
3
150 Views
Last Modified: 2016-02-15
I'm trying to learn LINQ  - and use it to work through a huge XML string that gets passed from QuickBooks.

The section of the XML i'm working with is:
<SubtotalRow rowNumber="52">
     <RowData rowType="item" value="BZ:FDV" />
     <ColData colID="1" value="Total FDV (J159 - $3.95 CND)" />
     <ColData colID="8" value="18" />
     <ColData colID="10" value="310.30" />
</SubtotalRow>

Open in new window


I'm trying to pull the values for RowData (value attribute) and ColData (colID and value attributes).
At the moment, I can pull the RowData or the ColData - but not both.  I'm assuming it would be some sort of "join" statement.  

Here's the code I have :
Dim xdoc = XDocument.Parse(responseMsgSet.ToXMLString)

        Dim results = (From n In xdoc.Root.Descendants("SubtotalRow") _
                       From c In n.Elements("ColData") _
                       Where c.Attribute("value") IsNot Nothing _
                       Select c.Attribute("value").Value).ToList()

        For Each value In results
            MsgBox("Value = " & value)
        Next

Open in new window


Any help would be appreciated!

Thanks!
0
Comment
Question by:slightlyoff
  • 2
3 Comments
 
LVL 63

Accepted Solution

by:
Fernando Soto earned 500 total points
ID: 40220830
Hi slightlyoff;

This modified code snippet should give you what you need.
Dim results = (From n In xdoc.Root.Descendants("SubtotalRow") _
               From c In n.Elements() _
               Where c.Attribute("value") IsNot Nothing _
               Select IF(c.Name = "RowData", c.Attribute("value").Value, c.Attribute("colID").Value & "|" & c.Attribute("value").Value  )).ToList()

For Each value In results
    If value.Contains("|") Then    
        Console.WriteLine("ColID = " & value.Substring(0, value.IndexOf("|")) & vbTab & "Value = " & value.Substring(value.IndexOf("|") + 1))
    Else
        Console.WriteLine("Value = " & value)
    End If
Next

Open in new window

0
 
LVL 1

Author Closing Comment

by:slightlyoff
ID: 40224255
Thanks for your help!  I really appreciate it!
0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 40224261
Not a problem, glad I was able to help.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Passing data between Forms 3 20
System.net.Sockets Error 5 28
Select question from MySQL 1 13
SQL Recursion 6 20
The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

827 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question