Hi,
I'm trying to perform an outer join on two xml documents using the following code:
// load two xml files
XElement input = XElement.Load(@"c:\temp\input.xml");
XElement output = XElement.Load(@"c:\temp\output.xml");
var root = new XElement("Response",
from p in input.Descendants("Row")
join c in output.Descendants("Row")
on
(string)p.Attribute("id")
equals
(string)c.Attribute("id")
into g
from c in g.DefaultIfEmpty()
select new XElement("Row",
new XAttribute("id", (string)p.Attribute("id")),
c,
p
));
Console.WriteLine(root);
The structure of a node in the input document:
<Row id="1">
<InputLine>COMPANY,TITLE,CONTACT,FIRST NAME,MIDDLE NAME,LAST NAME,ADDRESS,ADDRESS2,CITY,STATE,ZIP,ZIP4,PHONE,PHONE TYPE,SIC CODE,INC DATE,BIZ TYPE,OUTLET NUMBER,COUNTY,FIPS,S/C,LOC CODE,FRQ,OWNER ADDRESS,OWNER ADDRESS2,OWNER CITY,OWNER STATE,OWNER ZIP,OWNER PHONE,DESCRIPTION,RT DATE,EMAIL,NAICS,CONTACT 2 ADDRESS 2,CONTACT 2 CITY,CONTACT 2 STATE,CONTACT 2 ZIP,CONTACT 2 PHONE,CONTACT 3,CONTACT 3 ADDRESS,CONTACT 3 ADDRESS 2,CONTACT 3 CITY,CONTACT 3 STATE,CONTACT 3 ZIP,REG AGENT,REG ADDRES,REG ADDRESS2,REG CITY,REG STATE,REG ZIP,REG ZIP4,CONTRIBUTOR NUMBER,Q1,Q2,L1,L2,L3,L4,Consumer Phone,Line Type,Time Zone</InputLine>
The structure of a node in the output document:
<Row id="1">
<BusinessName>COMPANY</BusinessName>
<StreetAddress>ADDRESS</StreetAddress>
<State>ST</State>
<City>City</City>
<RequestId>1</RequestId>
<HouseNumber></HouseNumber>
<StreetName>Address</StreetName>
<PostalCode></PostalCode>
<Plus></Plus>
<TimeZone></TimeZone>
The goal is to join the documents and combine the elements from the input node and output node into a single node.
For a reason unknown to me a complete copy of the input and output node is being inserted into the newly created node instead of just the descendant nodes. I've tried c.Descendants() but I get a null reference error.
Any ideas?
Thanks, Chris