diff --git a/Libraries/UniversalEditor.Essential/DataFormats/Markup/XML/CommonXMLSchemas.cs b/Libraries/UniversalEditor.Essential/DataFormats/Markup/XML/CommonXMLSchemas.cs new file mode 100644 index 00000000..773bbb42 --- /dev/null +++ b/Libraries/UniversalEditor.Essential/DataFormats/Markup/XML/CommonXMLSchemas.cs @@ -0,0 +1,62 @@ +// +// XMLSchemas.cs - provides common XML schema definitions used in a wide variety of applications +// +// Author: +// Michael Becker +// +// Copyright (c) 2021 Mike Becker's Software +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +using System; +namespace UniversalEditor.DataFormats.Markup.XML +{ + /// + /// Provides common XML schema definitions used in a wide variety of applications. + /// + public static class CommonXMLSchemas + { + /// + /// The /elements/1.1/ namespace was created in 2000 for the RDF representation of the fifteen-element + /// Dublin Core and has been widely used in data for more than twenty years. This namespace corresponds + /// to the original scope of ISO 15836, which was published first in 2003 and last revised in 2017 as + /// ISO 15836-1:2017. + /// + /// The XML schema for the original Dublin Core namespace. + public static string DublinCore { get; } = "http://purl.org/dc/elements/1.1/"; + /// + /// The /terms/ namespace was originally created in 2001 for identifying new terms coined outside of the + /// original fifteen-element Dublin Core. In 2008, in the context of defining formal semantic constraints + /// for DCMI metadata terms in support of RDF applications, the original fifteen elements themselves were + /// mirrored in the /terms/ namespace. As a result, there exists both a dc:date (http://purl.org/dc/elements/1.1/date) + /// with no formal range and a corresponding dcterms:date (http://purl.org/dc/terms/date) with a formal + /// range of "literal". While these distinctions are significant for creators of RDF applications, most users + /// can safely treat the fifteen parallel properties as equivalent. The most useful properties and classes of + /// DCMI Metadata Terms have now been published as ISO 15836-2:2019 [ISO 15836-2:2019]. While the /elements/1.1/ + /// namespace will be supported indefinitely, DCMI gently encourages use of the /terms/ namespace. + /// + /// The XML schema for the Dublin Core Terms namespace. + public static string DublinCoreTerms { get; } = "http://purl.org/dc/terms/"; + /// + /// The /dcmitype/ namespace was created in 2001 for the DCMI Type Vocabulary, which defines classes for + /// basic types of thing that can be described using DCMI metadata terms. + /// + /// The XML schema for the Dublin Core DCMI Type namespace. + public static string DublinCoreDCMIType { get; } = "http://purl.org/dc/dcmitype/"; + /// + /// The /dcam/ namespace was created in 2008 for terms used in the description of DCMI metadata terms. + /// + /// The XML schema for the Dublin Core DCAM namespace. + public static string DublinCoreDCAM { get; } = "http://purl.org/dc/dcam/"; + } +} diff --git a/Libraries/UniversalEditor.Essential/DataFormats/Markup/XML/XMLDataFormat.cs b/Libraries/UniversalEditor.Essential/DataFormats/Markup/XML/XMLDataFormat.cs index d4c1964b..e1720aa6 100644 --- a/Libraries/UniversalEditor.Essential/DataFormats/Markup/XML/XMLDataFormat.cs +++ b/Libraries/UniversalEditor.Essential/DataFormats/Markup/XML/XMLDataFormat.cs @@ -21,7 +21,7 @@ using System; using System.Collections.Generic; - +using System.Text; using UniversalEditor.ObjectModels.Markup; using UniversalEditor.ObjectModels.PropertyList; @@ -116,7 +116,7 @@ namespace UniversalEditor.DataFormats.Markup.XML if (element is MarkupTagElement) { MarkupTagElement tag = element as MarkupTagElement; - tw.Write(indent + Settings.TagBeginChar.ToString() + element.FullName); + tw.Write(indent + Settings.TagBeginChar.ToString() + GetFullName(element)); if (tag.Attributes.Count > 0) { tw.Write(" "); @@ -199,6 +199,40 @@ namespace UniversalEditor.DataFormats.Markup.XML } } } + + private string GetFullName(MarkupElement element) + { + if (element is MarkupTagElement) + { + if ((element as MarkupTagElement).XMLSchema != null) + { + StringBuilder sb = new StringBuilder(); + sb.Append(GetPrefixForXMLSchema(element.ParentObjectModel, (element as MarkupTagElement).XMLSchema)); + sb.Append(':'); + sb.Append(element.Name); + return sb.ToString(); + } + } + return element.FullName; + } + + private string GetPrefixForXMLSchema(MarkupObjectModel mom, string xmlSchema) + { + foreach (MarkupElement el in mom.Elements) + { + if (el is MarkupTagElement) + { + foreach (MarkupAttribute att in (el as MarkupTagElement).Attributes) + { + if (att.Namespace == "xmlns" && att.Value == xmlSchema) + return att.Name; + } + break; + } + } + throw new InvalidOperationException(String.Format("xml prefix not found for schema '{0}'", xmlSchema)); + } + public void WriteStartDocument() { this.WriteStartPreprocessor("xml"); diff --git a/Libraries/UniversalEditor.Essential/ObjectModels/Markup/MarkupContainerElement.cs b/Libraries/UniversalEditor.Essential/ObjectModels/Markup/MarkupContainerElement.cs index 0d142c5f..19b12a4b 100644 --- a/Libraries/UniversalEditor.Essential/ObjectModels/Markup/MarkupContainerElement.cs +++ b/Libraries/UniversalEditor.Essential/ObjectModels/Markup/MarkupContainerElement.cs @@ -83,10 +83,14 @@ namespace UniversalEditor.ObjectModels.Markup return basetag; } + private string _XMLSchema = null; public string XMLSchema { get { + if (_XMLSchema != null) + return _XMLSchema; + if (this.Namespace == null) return null; @@ -103,6 +107,33 @@ namespace UniversalEditor.ObjectModels.Markup return null; } + set + { + if (this.ParentObjectModel == null) + { + _XMLSchema = value; + return; + } + + for (int i = 0; i < this.ParentObjectModel.Elements.Count; i++) + { + MarkupTagElement tagTopLevel = (this.ParentObjectModel.Elements[i] as MarkupTagElement); + if (tagTopLevel == null) + continue; + + foreach (MarkupAttribute att in tagTopLevel.Attributes) + { + if (att.Namespace == "xmlns") + { + if (att.Value == value) + { + Namespace = att.Name; + break; + } + } + } + } + } } protected override void UpdateParentObjectModel() diff --git a/Libraries/UniversalEditor.Essential/ObjectModels/Markup/MarkupTagElement.cs b/Libraries/UniversalEditor.Essential/ObjectModels/Markup/MarkupTagElement.cs index dd84d596..f939b80e 100644 --- a/Libraries/UniversalEditor.Essential/ObjectModels/Markup/MarkupTagElement.cs +++ b/Libraries/UniversalEditor.Essential/ObjectModels/Markup/MarkupTagElement.cs @@ -29,6 +29,21 @@ namespace UniversalEditor.ObjectModels.Markup /// public class MarkupTagElement : MarkupContainerElement { + public MarkupTagElement() + { + } + public MarkupTagElement(string fullName, string innerMarkup) + { + FullName = fullName; + Value = innerMarkup; + } + public MarkupTagElement(string schema, string name, string innerMarkup) + { + XMLSchema = schema; + Name = name; + Value = innerMarkup; + } + /// /// Combines the attributes and child elements of this with the given . /// diff --git a/Libraries/UniversalEditor.Essential/UniversalEditor.Essential.csproj b/Libraries/UniversalEditor.Essential/UniversalEditor.Essential.csproj index 575fa508..da6d2b1e 100644 --- a/Libraries/UniversalEditor.Essential/UniversalEditor.Essential.csproj +++ b/Libraries/UniversalEditor.Essential/UniversalEditor.Essential.csproj @@ -217,6 +217,7 @@ +