简体   繁体   中英

exporting XmlDocument to excel

I have a XmlDocument in which i have hierarchical data and i want to export this data to excel. Please help me to get out of this. I have tried to read this data into a dataset but it is not working for me.

Please send xml sample for more information.

Your code loads xml into dataset, so, if your xml doesn't exported from DataSet, you could use LinqToXml. for example:

xml:

<?xml version="1.0" encoding="utf-8" ?>
<rss version="2.0">
<channel>
    <title>Business Logic Toolkit for .NET</title>
    <link>http://www.bltoolkit.net</link>
    <description />
    <lastBuildDate>2009-01-11</lastBuildDate>
    <item>
        <title>Version 3.1 released</title>
        <link>http://www.bltoolkit.net/Download.htm</link>
        <description>See &lt;a href="http://www.bltoolkit.net/Download.htm"&gt;change log&lt;/a&gt;</description>
        <pubDate>2009-01-11</pubDate>
    </item>
    <item>
        <title>Version 3.0 released</title>
        <link>http://www.bltoolkit.net/Download.htm</link>
        <description>See &lt;a href="http://www.bltoolkit.net/Download.htm"&gt;change log&lt;/a&gt;</description>
        <pubDate>2008-05-21</pubDate>
    </item>
    <item>
        <title>New examples</title>
        <link>http://www.bltoolkit.net/Doc/</link>
        <description>See the following &lt;a href="http://www.bltoolkit.net/Doc/"&gt;link&lt;/a&gt;</description>
        <pubDate>2008-05-10</pubDate>
    </item>
</channel>
</rss>

this code get all rss items title

var path = @"D:\rss.xml";
var doc = XDocument.Load(path);
rssTitles = doc.Root.Descendants("item").Elements("title").Select(el => el.Value);

results:

Version 3.1 released
Version 3.0 released
New examples
<Roles>
  <BalanceSheets RoleURL="http://fluor.com/role/BalanceSheets" RoleDefination="0020 - CONDENSED CONSOLIDATED BALANCE SHEET">
    <Taxonomys>
      <StatementOfFinancialPositionAbstract TaxonomyPresentationId="StatementOfFinancialPositionAbstract">
        <StatementLineItems TaxonomyPresentationId="StatementOfFinancialPositionAbstract">
          <LiabilitiesAndStockholdersEquityAbstract TaxonomyPresentationId="StatementLineItems">
            <CommitmentsAndContingencies TaxonomyPresentationId="LiabilitiesAndStockholdersEquityAbstract" />
            <OtherLiabilitiesNoncurrent TaxonomyPresentationId="LiabilitiesAndStockholdersEquityAbstract" />
            <NonRecourseProjectFinanceDebtNoncurrent TaxonomyPresentationId="LiabilitiesAndStockholdersEquityAbstract" />
            <LongTermDebtNoncurrent TaxonomyPresentationId="LiabilitiesAndStockholdersEquityAbstract" />
            <LiabilitiesCurrentAbstract TaxonomyPresentationId="LiabilitiesAndStockholdersEquityAbstract">
              <BillingsInExcessOfCost TaxonomyPresentationId="LiabilitiesCurrentAbstract" />
              <LiabilitiesCurrent TaxonomyPresentationId="LiabilitiesCurrentAbstract" />
              <AccountsPayable TaxonomyPresentationId="LiabilitiesCurrentAbstract" />
              <BridgeLoan TaxonomyPresentationId="LiabilitiesCurrentAbstract" />
              <NonRecourseProjectFinanceDebtCurrent TaxonomyPresentationId="LiabilitiesCurrentAbstract" />
              <EmployeeRelatedLiabilities TaxonomyPresentationId="LiabilitiesCurrentAbstract" />
              <OtherAccruedLiabilities TaxonomyPresentationId="LiabilitiesCurrentAbstract" />
              <ConvertibleDebtCurrent TaxonomyPresentationId="LiabilitiesCurrentAbstract" />
            </LiabilitiesCurrentAbstract>
          </LiabilitiesAndStockholdersEquityAbstract>
        </StatementLineItems>
      </StatementOfFinancialPositionAbstract>
    </Taxonomys>
  </BalanceSheets>
</Roles>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM