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
Solved

Convert xml to csv - 2

Posted on 2015-01-26
2
103 Views
Last Modified: 2016-02-16
This is a follow on from
http://www.experts-exchange.com/Programming/Languages/C_Sharp/Q_28600021.html#a40568776

The file I want to use is nearly 8GB.  How can I filter the Linq query to only show a particular OrganizationID or organizationNameTypeCode or OrganizationName_effectiveTo?
0
Comment
Question by:AlHal2
2 Comments
 
LVL 63

Accepted Solution

by:
Fernando Soto earned 500 total points
ID: 40571467
Hi AlHal2;

Something like the following code snippet, where the where clause was modified.

// The values to filter on
string origId = "4295856130";
string typeName = "AKA";
string effectiveTo = "2005-08-18T04:00:00";

XElement doc = XElement.Load(@"C:\Working Directory\OAOrganization-File.xml");
string csv = (from el in doc.Descendants()
              let ns = String.Format("{{{0}}}",el.Name.NamespaceName)
              where  el.Name.LocalName == "Organization" && ((el.Element(ns + "OrganizationId").Value == origId) || 
                    (el.Element(ns + "OrganizationName").Attribute("organizationNameTypeCode").Value == typeName) ||
                    (el.Element(ns + "OrganizationName").Attribute("effectiveTo").Value == effectiveTo))
              select String.Format("{0},{1},{2},{3}",
              (string)el.Element(ns + "OrganizationId"),
              (string)el.Element(ns + "AdminStatus").Attribute("effectiveFrom"),
              (string)el.Element(ns + "AdminStatus"),
              Environment.NewLine
              )
              )
              .Aggregate( new StringBuilder(),  (sb, s) => sb.Append(s), sb => sb.ToString()
              );

Open in new window

0
 

Author Closing Comment

by:AlHal2
ID: 40572295
Thanks.
0

Featured Post

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

790 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