我有一個Datatable Cities包含以下數據(我發佈的60000個項目中只有3個)。如何從數據表生成xml文件
我想從提供的數據中創建一個xml(KML)。
如何創建通用解決方案?
也許創建類和添加屬性,然後加載到XML。
這將是generated.i我只張貼的部分XML
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2"
xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:json="http://www.w3.org/2005/Json">
<Folder>
<name>USA</name>
<open>1</open>
<Folder>
<name>Corperation</name>
<open>1</open>
<Folder>
<name>LARGE</name>
<Folder>
<name>WORKING</name>
<Document>
<name>POINTS</name>
<StyleMap id="Licerio0_0">
<Pair>
<key>normal</key>
<styleUrl>#Licerio0_0N</styleUrl>
</Pair>
<Pair>
<key>highlight</key>
<styleUrl>#Licerio0_0H</styleUrl>
</Pair>
</StyleMap>
<Style id="Licerio0_0N">
<IconStyle>
<color>ff00ff00</color>
<scale>0.4</scale>
<Icon>
http://maps.google.com/mapfiles/kml/shapes/shaded_dot.png
</Icon>
</IconStyle>
<LabelStyle>
<color>ff00ff00</color>
<scale>0.6</scale>
</LabelStyle>
<BalloonStyle>
<text>$[description]</text>
</BalloonStyle>
<LineStyle>
<antialias>0</antialias>
</LineStyle>
<PolyStyle>
<fill>0</fill>
<outline>0</outline>
</PolyStyle>
</Style>
<Placemark>
<name>NEWYORK</name>
<description>
<![CDATA[<img src="http://upload.wikimedia.org/wikipedia/commons/USA.png"width="47" height="67">
<br>RSID = <b>NEWYORK</b><ul>
<li>PIN = 676306
<li>LONGITUDE = 54.4251
<li>LATITUDE = 25.6011
<li>SCALE = 0.7
<li>TOTAL TILT = 4
<li>CH = 87
<li>REGION = NEM</ul></li>]]>
</description>
<styleUrl>#Licerio0_0</styleUrl>
<Point>
<gx:drawOrder>3</gx:drawOrder>
<coordinates>54.4251,25.6011,0</coordinates>
</Point>
</Placemark>
</Document>
*
*<Document>
<name>LINES</name>
<Style id="Zamoras0_0">
</Style>
<Placemark>
<name>***Site Id***</name>
<styleUrl>#Zamoras0_0</styleUrl>
<MultiGeometry>
<LineString>
<gx:drawOrder>3</gx:drawOrder>
<coordinates>***LONGITUDE***,***LATITUDE***,***SCALE***</coordinates>
</LineString>
</MultiGeometry>
</Placemark>
</Document>**
</Folder>
</Folder>
</Folder>
.
.
ETC.......
</Folder>
</kml>
編輯 模板小的變化,這兩個文件是一個LINES
和其他有對於POINTS
。如果我有內部街道,那麼它應該被添加在兩個文檔section.i編輯我的問題的地標。如何做到這一點?如果我使用此代碼,它我s複製
dt.Columns.Add("countryname", typeof(string));
dt.Columns.Add("citytype", typeof(string));
dt.Columns.Add("size", typeof(string));
dt.Columns.Add("status", typeof(string));
dt.Columns.Add("cityname", typeof(string));
dt.Columns.Add("pin", typeof(int));
dt.Columns.Add("LONGITUDE", typeof(double));
dt.Columns.Add("LATITUDE", typeof(double));
dt.Columns.Add("SCALE", typeof(double));
dt.Columns.Add("TOTAL", typeof(int));
dt.Columns.Add("TILT", typeof(string));
dt.Columns.Add("CH", typeof(string));
dt.Columns.Add("REGION", typeof(string));
dt.Columns.Add("streets", typeof(string));
dt.Rows.Add(new object[] { "USA", "Corperation", "LARGE", "WORKING", "newyork", 676306, 24.4251, 25.6011, 0.0, 87, "NEM","firststreet" });
dt.Rows.Add(new object[] { "USA", "Corperation", "LARGE", "WORKING", "newyork", 676306, 24.4251, 25.6011, 0.0, 87, "NEM","downtownstreet" });
dt.Rows.Add(new object[] { "USA", "Corperation", "LARGE", "WORKING", "chicago", 676306, 24.4251, 25.6011, 0.0, 87, "NEM","chicstreet" });
dt.Rows.Add(new object[] { "USA", "Corperation", "LARGE", "WORKING", "la", 676306, 24.4251, 25.6011, 0.0, 87, "NEM","lastreet" });
dt.Rows.Add(new object[] { "USA", "Corperation", "MEDIUM", "WORKING", "buffalo", 676306, 24.4251, 25.6011, 0.0, 87, "NEM","buffalostreet" });
dt.Rows.Add(new object[] { "USA", "Corperation", "MEDIUM", "WORKING", "buffalo", 676306, 24.4251, 25.6011, 0.0, 87, "NEM","cowstreet" });
dt.Rows.Add(new object[] { "USA", "Corperation", "MEDIUM", "WORKING", "denver", 676306, 24.4251, 25.6011, 0.0, 87, "NEM","street" });
dt.Rows.Add(new object[] { "USA", "Corperation", "MEDIUM", "NOT WORKING", "lasvegas", 676306, 24.4251, 25.6011, 0.0, 87, "NEM","street" });
dt.Rows.Add(new object[] { "USA", "Corperation", "SMALL", "WORKING", "trenton", 676306, 24.4251, 25.6011, 0.0, 87, "NEM" ,"street"});
dt.Rows.Add(new object[] { "USA", "Village", "SMALL", "WORKING", "albany", 676306, 24.4251, 25.6011, 0.0, 87, "NEM","street" });
dt.Rows.Add(new object[] { "USA", "Village", "SMALL", "WORKING", "hartford", 676306, 24.4251, 25.6011, 0.0, 87, "NEM","street" });
dt.Rows.Add(new object[] { "SPAIN", "Corperation", "MEDIUM", "WORKING", "BARCELONA", 11111, 34.4251, 25.6011, 0.0, 82, "LEV" });
dt.Rows.Add(new object[] { "ITALY", "Corperation", "LARGE", "WORKING", "ITALY", 21111, 14.4251, 15.6011, 0.0, 80, "MIR" });
代碼有什麼你試過嗎? – CodeNotFound
你可以加載數據到一個DataSet然後使用編寫結果一個XML文件在下面的'C#Stackoverflow導出數據表到XML文件'做一個谷歌搜索 – MethodMan
DataTable附帶一個[WriteToXml方法](https://msdn.microsoft .com/en-us/library/system.data.datatable.writexml(v = vs.110).aspx)...只需使用Xslt轉換生成的Xml。不應該太難。 – Filburt