views:

37

answers:

1

IBM only provides a database connection to the iSeries, thus I have to work around this issue with using a table to pass data from the iSeries to .NET. The RPGLE program creates an XML document in a table for processing on the .NET side. The thing is that on one record in the table has one line of the XML document.

To help visualize pretend that there is an auto-increment primary key.

  1  <?xml version="1.0" encoding="utf-8" ?>
  2  <displayFile name="APDS001FM">
  3  <recordFormatname="SFL1">
  4  <fieldName name="*IN12" io="I" type="alpha" len="1">0</fieldName>
  5  <fieldName name="WLINE" io="O" type="alpha" len="79">PURCHASE ORDER</fieldName>
  6  </recordFormat>
  7  </displayFile>

I need to parse this out to get at the "WLINE" data (in this case "PURCHASE ORDER").

What would be the best approach to get the records out of the table into a XDocument so I can easily work with the XML.

I tried loading all of the records into a string. But XDocument doesn't seem have to have a way to load it from a string.

// Retieve the XML and process it.
XMLOUTPTableAdapter xmlOutTA = new XMLOUTPTableAdapter();
DataLayer.DataSet1.XMLOUTPDataTable xmlOutDT = xmlOutTA.GetData();
foreach (DataLayer.DataSet1.XMLOUTPRow row in xmlOutDT)
{
  xmlString += row.XMLLINE;
}

// Create and XML Document
XDocument xmlDoc = XDocument.Load(xmlString);

Is what I was hoping to do.

+2  A: 

You can load an XDocument from a string with XDocument.Parse(string text).

GraemeF
My first time working with LINQ. I missed that and it didn't turn up in my web searches. Thanks!
Mike Wills