i want to convert this xml to c# code? [closed]
<?xml version="1.0" encoding="utf-8"?>
<Report xmlns="http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition" xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner">
<Width>6.5in</Width>
<Body>
<Height>2in</Height>
</Body>
<rd:InitialLanguage>true</rd:InitialLanguage>
<rd:InitialDimensions>
<rd:UnitType>Inch</rd:UnitType>
<rd:LeftMargin>1in</rd:LeftMargin>
<rd:RightMargin>1in</rd:RightMargin>
<rd:TopMargin>1in</rd:TopMargin>
<rd:BottomMargin>1in</rd:BottomMargin>
<rd:PageWidth>8.5in</rd:PageWidth>
<rd:PageHeight>11in</rd:PageHeight>
<rd:ColumnSpacing>0.5in</rd:ColumnSpacing>
</rd:InitialDimensions>
<rd:InitialDimensions>
<rd:UnitType>Cm</rd:UnitType>
<rd:Width>16cm</rd:Width>
<rd:Height>5cm</rd:Height>
<rd:LeftMargin>2.5cm</rd:LeftMargin>
<rd:RightMargin>2.5cm</rd:RightMargin>
<rd:TopMargin>2.5cm</rd:TopMargin>
<rd:BottomMargin>2.5cm</rd:BottomMargin>
<rd:GridSpacing>0.25cm</rd:GridSpacing>
开发者_开发知识库 <rd:PageWidth>21cm</rd:PageWidth>
<rd:PageHeight>29.7cm</rd:PageHeight>
<rd:ColumnSpacing>1cm</rd:ColumnSpacing>
</rd:InitialDimensions>
</Report>
You can check out LINQ to XML on how to parse XML. Since you don't seem to have a specific question, here a sample on how you could read the value of the first Width element in your xml:
XDocument doc = XDocument.Load(@"test.xml");
var width = doc.Descendants("Width").First().Value;
First, generate a schema for the xml:
xsd.exe "yourXml.xml"
This will generate a yourXml.xsd
file containing a xml schema. Verify that this schema describes what you want reflected in your class.
Once your satisfied with the schema, use xsd.exe
to generate classes:
xsd.exe "yourXml.xsd" /c
note: if you want to generate a DataSet
class instead, use /d
.
精彩评论