Solved

LINQ join together

Posted on 2014-07-25
3
147 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
Comment Utility
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
Comment Utility
Thanks for your help!  I really appreciate it!
0
 
LVL 62

Expert Comment

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

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

744 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

13 Experts available now in Live!

Get 1:1 Help Now