The following LINQ to XML C# code creates one XElement
having one XAttribute
:
XElement xWorksheet =
new XElement("Worksheet", new XAttribute(XName.Get("Name", "ss"), "Sheet1"));
It generates an inline namespace producing the following XML element having p1:
<Worksheet p1:Name="Sheet1" xmlns:p1="ss" />
However what I really want is this:
<Worksheet ss:Name="Sheet1" />
How can I get the second form of the element?
Note: If you recognize the XML structure, I'm filling out an Excel spreadsheet but this is anecdotal to the question.
Ultimately I'm creating the Worksheet element in the following Excel document:
<?xml version="1.0"?>
<?mso-application progid="Excel.Sheet"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:html="http://www.w3.org/TR/REC-html40">
<Worksheet ss:Name="Sheet1">
<Table>
<Row>
<Cell>
<Data ss:Type="String">number </Data>
</Cell>
<Cell>
<Data ss:Type="String">name </Data>
</Cell>
</Row>
</Table>
</Worksheet>
</Workbook>