2017-10-13 5 views
-1

xsd에서 xml을 생성하고 싶습니다.이 xml xsd에서 속성을 지정하고 싶습니다. 어떤 아이디어?ado.net과 Xsd에서 Xml 생성

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

이것은 내용이 좋지 않습니다. 읽을 수없고 너무 광범위합니다. 다음 내용을 읽어보십시오. https://stackoverflow.com/help/asking –

답변

0

xsd.exe를 살펴보십시오. 이것을 XSD에 대해 실행하면 XSD 요소와 속성을 기반으로 클래스가 제공됩니다. 그 후에 원시 XML 또는 XSD로 작업 할 필요가 없습니다.