XML Schema embedded

pull/460/merge^2
Buddhika Chathuranga 2020-04-13 09:40:50 +05:30
parent 2bc768e92f
commit 5821bd9b92
3 changed files with 40 additions and 3 deletions

View File

@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Text;
using System.Xml;
using System.Xml.Schema;
@ -104,13 +105,23 @@ namespace winsw
{
XmlReaderSettings settings = new XmlReaderSettings();
Assembly a = Assembly.GetExecutingAssembly();
string[] resourceNames = this.GetType().Assembly.GetManifestResourceNames();
try
{
settings.Schemas.Add(null, BasePath + ".xsd");
}
catch (FileNotFoundException)
using (Stream schemaStream = a.GetManifestResourceStream("winsw.XMLSchema.xsd"))
{
throw new FileNotFoundException("XSD file not found");
using (XmlReader schemaReader = XmlReader.Create(schemaStream))
{
settings.Schemas.Add(null, schemaReader);
}
}
}
catch(Exception e)
{
throw e;
}
settings.ValidationType = ValidationType.Schema;

View File

@ -9,6 +9,10 @@
<SignAssembly>true</SignAssembly>
</PropertyGroup>
<ItemGroup>
<None Remove="XMLSchema.xsd" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="log4net" Version="2.0.8" />
</ItemGroup>
@ -44,4 +48,8 @@
<PackageReference Include="SharpZipLib" Version="0.86.0" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="XMLSchema.xsd" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,18 @@
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="https://www.w3schools.com"
xmlns="https://www.w3schools.com"
elementFormDefault="qualified">
<xs:element name="service">
<xs:complexType>
<xs:sequence>
<xs:element name="id" type="xs:string"/>
<xs:element name="name" type="xs:string"/>
<xs:element name="description" type="xs:string"/>
<xs:element name="executable" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>