-
Notifications
You must be signed in to change notification settings - Fork 4.6k
/
SchemaUtils.cs
54 lines (49 loc) · 1.69 KB
/
SchemaUtils.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.IO;
using System.Text;
using System.Xml;
using System.Xml.Schema;
using Xunit;
namespace System.Runtime.Serialization.Xml.XsdDataContractExporterTests
{
internal class SchemaUtils
{
internal static string SerializationNamespace = "http://schemas.microsoft.com/2003/10/Serialization/";
static XmlWriterSettings writerSettings = new XmlWriterSettings() { Indent = true };
public static string OrderedContains(string expected, ref string actual)
{
Assert.Contains(expected, actual);
actual = actual.Substring(actual.IndexOf(expected));
return actual;
}
public static string DumpSchema(XmlSchemaSet schemas)
{
StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
foreach (XmlSchema schema in schemas.Schemas())
{
if (schema.TargetNamespace != SerializationNamespace)
{
schema.Write(sw);
}
sw.WriteLine();
}
sw.Flush();
return sb.ToString();
}
internal static XmlSchema GetSchema(XmlSchemaSet schemaSet, string targetNs)
{
XmlSchema schema = null;
foreach (XmlSchema ctSchema in schemaSet.Schemas())
{
if (ctSchema.TargetNamespace == targetNs)
{
schema = ctSchema;
break;
}
}
return schema;
}
}
}