Solved

LINQ join together

Posted on 2014-07-25
3
153 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

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 post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

691 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