-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathXMLearning.cs
More file actions
49 lines (40 loc) · 1.4 KB
/
XMLearning.cs
File metadata and controls
49 lines (40 loc) · 1.4 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using System;
using System.Linq;
using System.Xml;
using System.Xml.Linq;
using System.Xml.Schema;
namespace vscode
{
public static class XMLearning
{
public static void Run()
{
string xml = @"
<customer id='123' middle='middle' status='archived'>
<firstname>Joe</firstname>
<lastname>Bloggs></lastname>
</customer>
";
XElement customer = XElement.Parse(xml);
var test = customer.FirstNode;
XDocument xdoc = XDocument.Load("CustomerOrders.xml");
XmlSchemaSet xschemas = new XmlSchemaSet();
xschemas.Add(null, "CustomerOrders.xsd");
//Console.WriteLine(xdoc.FirstNode.ToString());
bool errors = false;
xdoc.Validate(xschemas, (o, e) =>
{
Console.WriteLine("{0}", e.Message);
errors = true;
}, true);
Console.WriteLine("doc1 {0}", errors ? "did not validate" : "validated");
XElement xe = XElement.Load("CustomerOrders.xml");
var orders = from o in xe.Elements(name: "Orders")
select o.ToString();
foreach(var s in orders)
{
Console.WriteLine(s);
}
}
}
}