?
Solved

LINQ join together

Posted on 2014-07-25
3
Medium Priority
?
163 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 2000 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

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.
This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses
Course of the Month9 days, 11 hours left to enroll

762 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