首页 > 代码库 > xml

xml

public static String generateXSD(string xmlPath)
{

XmlReader reader = XmlReader.Create(xmlPath);
XmlSchemaSet schemaSet = new XmlSchemaSet();
String xsdPath = "e:\\temp.xsd";
XmlWriter writer;
int count = 0;
StringBuilder sb = new StringBuilder();
XmlSchemaInference schema = new XmlSchemaInference();
schemaSet = schema.InferSchema(reader);

foreach (XmlSchema s in schemaSet.Schemas())
{
writer = XmlWriter.Create(sb);
foreach (XmlSchemaElement element in s.Elements.Values)
{
XmlSchemaComplexType complexType = element.ElementSchemaType as XmlSchemaComplexType;
complexType.IsMixed = false;
}

s.Write(writer);

writer.Close();

File.WriteAllText(xsdPath, sb.ToString().Replace("mixed=\"true\"", "mixed=\"false\""), Encoding.Unicode);

}

 

reader.Close();

return xsdPath;
}

xml