2012-10-23 28 views
0

可能重複:
How to create XSD file programmatically in C#?轉換的XDocument到XSD文件

我有一個XDocument對象,我想通過代碼將其轉換爲XSD文件

如何我應該怎麼做呢?

我的項目是這樣的:

WebClient client = new WebClient(); 
Stream stream = client.OpenRead("http://maps.googleapis.com/maps/api/distancematrix/xml?origins=Vancouver+BC|Seattle&destinations=San+Francisco|Vancouver+BC&mode=bicycling&language=fr-FR&sensor=false"); 
XDocument doc = XDocument.Load(stream); 

回答

2

只要將它保存在XSD擴展,如果加載XMLXDocument對象是符合XSD格式。

WebClient client = new WebClient(); 
Stream stream = client.OpenRead("http://maps.googleapis.com/maps/api/distancematrix/xml?origins=Vancouver+BC|Seattle&destinations=San+Francisco|Vancouver+BC&mode=bicycling&language=fr-FR&sensor=false"); 
XDocument doc = XDocument.Load(stream); 
// ... 
doc.Save(@"C:\AnyFileName.xsd"); 

ADDED:或者,如果XMLXSD格式,那麼您可以根據使用下面的代碼輸入XML生成XSD

doc.Save(@"C:\xmlFile.xml"); 
string parms = @"C:\File.xml /outputdir:C:\\"; 
string xsdExePath = @"C:\Program Files\...\xsd.exe"; 
ProcessStartInfo psi = new ProcessStartInfo(xsdExePath, parms); 
var process = System.Diagnostics.Process.Start(psi); 

現在你可以有你XSD可在C:\驅動器根。

+0

顯然,公佈的文件是不是XSD ... –

+0

坦克!!!!!!!!!!! –