-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathXsdInferrer.cs
35 lines (30 loc) · 958 Bytes
/
XsdInferrer.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
using System.IO;
using System.Linq;
using System.Xml;
using System.Xml.Linq;
using System.Xml.Schema;
namespace NaitonStore.App_Code.Utilites
{
public class XsdInferrer
{
public static XDocument InferXsdFromXml(XDocument doc)
{
XmlReader reader = doc.CreateReader();
XmlSchemaSet schemaSet = new XmlSchemaSet();
XmlSchemaInference inference = new XmlSchemaInference();
schemaSet = inference.InferSchema(reader);
var schema = schemaSet.Schemas().Cast<XmlSchema>().First();
using (var mem = new MemoryStream())
{
schema.Write(mem);
mem.Position = 0;
return XDocument.Load(mem);
}
}
public static XDocument InferXsdFromCsv(string text)
{
var xml = CsvToXmlConverter.ConvertCsvToXml(text);
return InferXsdFromXml(xml);
}
}
}