diff --git a/VECTO3GUI2020/Helper/XmlHelper.cs b/VECTO3GUI2020/Helper/XmlHelper.cs new file mode 100644 index 0000000000000000000000000000000000000000..75ea3988078864a3c4b590db9bc4f848cdf4170f --- /dev/null +++ b/VECTO3GUI2020/Helper/XmlHelper.cs @@ -0,0 +1,57 @@ +using System; +using System.Xml; +using Castle.Core.Internal; + +namespace VECTO3GUI2020.Helper +{ + public static class XmlHelper + { + public static XmlDocument ReadXmlDocument(string filePath) + { + if (filePath.IsNullOrEmpty()) + return null; + + var xmlDocument = new XmlDocument(); + + using (var reader = new XmlTextReader(filePath)) { + xmlDocument.Load(reader); + } + + return xmlDocument; + } + + + public static XmlNodeList GetComponentNodes(XmlDocument xmlDocument, string parentNode, string nodeName) + { + if (xmlDocument == null || parentNode.IsNullOrEmpty() || nodeName.IsNullOrEmpty()) + return null; + + return xmlDocument.SelectNodes($"//*[local-name()='{parentNode}']//*[local-name()='{nodeName}']"); + } + + //public static bool ValidateXDocument(XDocument xDocument, Action<bool> resultAction = null, + // Action<XmlSeverityType, ValidationEvent> validationErrorAction = null) + //{ + // var xmlDocument = xDocument.ToXmlDocument(); + // if (xmlDocument == null) + // return false; + + // var documentType = XMLHelper.GetDocumentType(xmlDocument.DocumentElement.LocalName); + // if (documentType == null) + // { + // throw new VectoException("unknown xml file! {0}", xmlDocument.DocumentElement.LocalName); + // } + + // var validator = new XMLValidator(xmlDocument, resultAction, validationErrorAction); + // return validator.ValidateXML(documentType.Value); ; + //} + + public static string GetXmlAbsoluteFilePath(string baseUri) + { + if (baseUri == null) + return null; + + return Uri.UnescapeDataString(new Uri(baseUri).AbsolutePath); + } + } +} diff --git a/VECTO3GUI2020/VECTO3GUI2020.csproj b/VECTO3GUI2020/VECTO3GUI2020.csproj index 2fa6a1e583edbc59b414380b49c403457f18cffa..f3e1c83aeceec0de48a903cbd413a92e65765ab8 100644 --- a/VECTO3GUI2020/VECTO3GUI2020.csproj +++ b/VECTO3GUI2020/VECTO3GUI2020.csproj @@ -137,6 +137,7 @@ <Compile Include="Helper\DialogHelper.cs" /> <Compile Include="Helper\WindowHelper.cs" /> <Compile Include="Helper\XMLExtension.cs" /> + <Compile Include="Helper\XmlHelper.cs" /> <Compile Include="Ninject\FactoryModule.cs" /> <Compile Include="Ninject\MultistageModule.cs" /> <Compile Include="Util\XML\Implementation\ComponentWriter\XMLPTOWriter.cs" />