我想从xsd生成xml,这个xml我想要包含来自xsd的指定属性。有什么想法吗?
string fn = System.IO.Path.GetFileName(File1.PostedFile.FileName);
string SaveLocation = Server.MapPath("Data") + "\\" + fn;
try
{
File1.PostedFile.SaveAs(SaveLocation);
Response.Write("The file has been uploaded.");
}
catch (Exception ex)
{
Response.Write("Error: " + ex.Message);
//Note: Exception.Message returns a detailed message that describes the current exception.
//For security reasons, we do not recommend that you return Exception.Message to end users in
//production environments. It would be better to put a generic error message.
}
try
{
XmlTextReader reader = new XmlTextReader(SaveLocation);
//XmlSchema myschema = XmlSchema.Read(reader, ValidationCallback);
while (reader.Read())
{
// LiteralURL.Text += reader.ReadString();
}
// Response.Write("\t"+myschema.Items);
XDocument doc = XDocument.Load(SaveLocation);
var ListNode = new List<XNode>();
if (doc != null)
{
Response.Write("nu este null");
}
else
{
Response.Write("Null !");
}
int i = 0;
string str = "";
foreach (XNode nodes in doc.Elements())
{
str = "node1: " + nodes.ToString();
ListNode[i] = nodes;
i++;
}
for(int j = 0; j < i; i++)
{
Response.Write("FirstNode:"+ ListNode[j]);
}
//Response.Write("FirstNode:" );
Response.Write(str);
}
catch (Exception ex)
{
}
}
else
{
Response.Write("Please select a file to upload.");
}
答案 0 :(得分:0)
看看xsd.exe。您针对XSD运行此操作,它会根据XSD元素和属性为您提供类。在此之后,您不需要使用原始XML或XSD。