Solved

LINQ join together

Posted on 2014-07-25
3
149 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 62

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 62

Expert Comment

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

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
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…

813 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now