lutaml-model 0.8.192 → 0.8.194

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1800,4 +1800,368 @@ new_c = Ceramic.new(
1800
1800
  puts new_c.to_xml
1801
1801
  # xsi:schemaLocation automatically included
1802
1802
  ----
1803
- ====
1803
+ ====
1804
+
1805
+ == Advanced namespace patterns
1806
+
1807
+ === Nested namespaced elements with inheritance
1808
+
1809
+ When working with deeply nested XML structures, LutaML::Model provides
1810
+ sophisticated namespace inheritance optimization. Elements that share the same
1811
+ namespace as their parent will inherit the namespace declaration, avoiding
1812
+ redundant `xmlns` attributes.
1813
+
1814
+ ==== Same namespace inheritance (UnitsML scenario)
1815
+
1816
+ When all nested models share the same namespace, the framework automatically
1817
+ inherits the namespace from the root element, producing clean XML without
1818
+ redundant namespace declarations.
1819
+
1820
+ .Models with shared namespace
1821
+ [example]
1822
+ ====
1823
+ [source,ruby]
1824
+ ----
1825
+ class UnitSystem < Lutaml::Model::Serializable
1826
+ attribute :name, :string
1827
+ attribute :type, :string
1828
+
1829
+ xml do
1830
+ root "UnitSystem"
1831
+ namespace "https://schema.example.org/units/1.0"
1832
+ map_attribute "name", to: :name
1833
+ map_attribute "type", to: :type
1834
+ end
1835
+ end
1836
+
1837
+ class UnitName < Lutaml::Model::Serializable
1838
+ attribute :value, :string
1839
+
1840
+ xml do
1841
+ root "UnitName"
1842
+ namespace "https://schema.example.org/units/1.0"
1843
+ map_content to: :value
1844
+ end
1845
+ end
1846
+
1847
+ class EnumeratedRootUnit < Lutaml::Model::Serializable
1848
+ attribute :unit, :string
1849
+ attribute :prefix, :string
1850
+
1851
+ xml do
1852
+ root "EnumeratedRootUnit"
1853
+ namespace "https://schema.example.org/units/1.0"
1854
+ map_attribute "unit", to: :unit
1855
+ map_attribute "prefix", to: :prefix
1856
+ end
1857
+ end
1858
+
1859
+ class RootUnits < Lutaml::Model::Serializable
1860
+ attribute :enumerated_root_units, EnumeratedRootUnit, collection: true
1861
+
1862
+ xml do
1863
+ root "RootUnits"
1864
+ namespace "https://schema.example.org/units/1.0"
1865
+ map_element "EnumeratedRootUnit", to: :enumerated_root_units
1866
+ end
1867
+ end
1868
+
1869
+ class Unit < Lutaml::Model::Serializable
1870
+ attribute :id, :string
1871
+ attribute :unit_system, UnitSystem
1872
+ attribute :unit_name, UnitName
1873
+ attribute :root_units, RootUnits
1874
+
1875
+ xml do
1876
+ root "Unit"
1877
+ namespace "https://schema.example.org/units/1.0"
1878
+ map_attribute "id", to: :id
1879
+ map_element "UnitSystem", to: :unit_system
1880
+ map_element "UnitName", to: :unit_name
1881
+ map_element "RootUnits", to: :root_units
1882
+ end
1883
+ end
1884
+ ----
1885
+
1886
+ [source,ruby]
1887
+ ----
1888
+ # Create nested structure
1889
+ unit_system = UnitSystem.new(name: "SI", type: "SI_derived")
1890
+ unit_name = UnitName.new(value: "meter")
1891
+ meter_unit = EnumeratedRootUnit.new(unit: "meter")
1892
+ gram_unit = EnumeratedRootUnit.new(unit: "gram", prefix: "k")
1893
+ root_units = RootUnits.new(enumerated_root_units: [meter_unit, gram_unit])
1894
+
1895
+ unit = Unit.new(
1896
+ id: "U_m",
1897
+ unit_system: unit_system,
1898
+ unit_name: unit_name,
1899
+ root_units: root_units
1900
+ )
1901
+ ----
1902
+
1903
+ Generated XML shows namespace declared only once on the root element:
1904
+
1905
+ [source,xml]
1906
+ ----
1907
+ <Unit xmlns="https://schema.example.org/units/1.0" id="U_m">
1908
+ <UnitSystem name="SI" type="SI_derived"/>
1909
+ <UnitName>meter</UnitName>
1910
+ <RootUnits>
1911
+ <EnumeratedRootUnit unit="meter"/>
1912
+ <EnumeratedRootUnit unit="gram" prefix="k"/>
1913
+ </RootUnits>
1914
+ </Unit>
1915
+ ----
1916
+
1917
+ *Key behaviors:*
1918
+
1919
+ * The `xmlns` declaration appears only on the root `Unit` element
1920
+ * All child elements (`UnitSystem`, `UnitName`, `RootUnits`, `EnumeratedRootUnit`) inherit the namespace
1921
+ * No redundant namespace declarations on child elements
1922
+ * Clean, optimized XML output following namespace inheritance best practices
1923
+ ====
1924
+
1925
+ ==== Mixed namespace handling
1926
+
1927
+ When different namespaces are used within the same document structure,
1928
+ LutaML::Model correctly manages namespace declarations, adding `xmlns` attributes
1929
+ only when the namespace changes from the parent element.
1930
+
1931
+ .Models with mixed namespaces
1932
+ [example]
1933
+ ====
1934
+ [source,ruby]
1935
+ ----
1936
+ class MathContent < Lutaml::Model::Serializable
1937
+ attribute :value, :string
1938
+
1939
+ xml do
1940
+ root "math"
1941
+ namespace "http://www.w3.org/1998/Math/MathML"
1942
+ map_content to: :value
1943
+ end
1944
+ end
1945
+
1946
+ class UnitSymbol < Lutaml::Model::Serializable
1947
+ attribute :type, :string
1948
+ attribute :math, MathContent
1949
+
1950
+ xml do
1951
+ root "UnitSymbol"
1952
+ namespace "https://schema.example.org/units/1.0"
1953
+ map_attribute "type", to: :type
1954
+ map_element "math", to: :math
1955
+ end
1956
+ end
1957
+
1958
+ class UnitWithMath < Lutaml::Model::Serializable
1959
+ attribute :id, :string
1960
+ attribute :unit_symbol, UnitSymbol
1961
+
1962
+ xml do
1963
+ root "Unit"
1964
+ namespace "https://schema.example.org/units/1.0"
1965
+ map_attribute "id", to: :id
1966
+ map_element "UnitSymbol", to: :unit_symbol
1967
+ end
1968
+ end
1969
+ ----
1970
+
1971
+ [source,ruby]
1972
+ ----
1973
+ # Create structure with mixed namespaces
1974
+ math = MathContent.new(value: "x+y")
1975
+ unit_symbol = UnitSymbol.new(type: "MathML", math: math)
1976
+ unit_with_math = UnitWithMath.new(id: "U_m.kg-2", unit_symbol: unit_symbol)
1977
+ ----
1978
+
1979
+ Generated XML correctly handles namespace transitions:
1980
+
1981
+ [source,xml]
1982
+ ----
1983
+ <Unit xmlns="https://schema.example.org/units/1.0" id="U_m.kg-2">
1984
+ <UnitSymbol type="MathML">
1985
+ <math xmlns="http://www.w3.org/1998/Math/MathML">x+y</math>
1986
+ </UnitSymbol>
1987
+ </Unit>
1988
+ ----
1989
+
1990
+ *Key behaviors:*
1991
+
1992
+ * The `Unit` element declares the units namespace (`https://schema.example.org/units/1.0`)
1993
+ * `UnitSymbol` inherits the same namespace from `Unit` (no xmlns needed)
1994
+ * `math` element declares its own namespace (`http://www.w3.org/1998/Math/MathML`) because it differs from the parent
1995
+ * Namespace declarations are added only where the namespace changes
1996
+ * Efficient XML with minimal namespace declarations
1997
+ ====
1998
+
1999
+ ==== Mixed nested namespace with multiple levels
2000
+
2001
+ For more complex scenarios involving multiple nesting levels with different
2002
+ namespaces at various depths, the framework handles each namespace transition
2003
+ appropriately.
2004
+
2005
+ .Complex mixed namespace structure
2006
+ [example]
2007
+ ====
2008
+ [source,ruby]
2009
+ ----
2010
+ # Define additional namespaces for deeper nesting
2011
+ class MetadataNamespace < Lutaml::Model::XmlNamespace
2012
+ uri "https://schema.example.org/metadata/1.0"
2013
+ prefix_default "meta"
2014
+ end
2015
+
2016
+ class AnnotationNamespace < Lutaml::Model::XmlNamespace
2017
+ uri "https://schema.example.org/annotation/1.0"
2018
+ prefix_default "ann"
2019
+ end
2020
+
2021
+ # Nested models with different namespaces at each level
2022
+ class Annotation < Lutaml::Model::Serializable
2023
+ attribute :text, :string
2024
+ attribute :author, :string
2025
+
2026
+ xml do
2027
+ root "annotation"
2028
+ namespace "https://schema.example.org/annotation/1.0"
2029
+ map_element "text", to: :text
2030
+ map_attribute "author", to: :author
2031
+ end
2032
+ end
2033
+
2034
+ class Metadata < Lutaml::Model::Serializable
2035
+ attribute :version, :string
2036
+ attribute :annotation, Annotation
2037
+
2038
+ xml do
2039
+ root "metadata"
2040
+ namespace "https://schema.example.org/metadata/1.0"
2041
+ map_attribute "version", to: :version
2042
+ map_element "annotation", to: :annotation
2043
+ end
2044
+ end
2045
+
2046
+ class ExtendedUnitSymbol < Lutaml::Model::Serializable
2047
+ attribute :type, :string
2048
+ attribute :math, MathContent # MathML namespace
2049
+ attribute :metadata, Metadata # Metadata namespace -> Annotation namespace
2050
+
2051
+ xml do
2052
+ root "UnitSymbol"
2053
+ namespace "https://schema.example.org/units/1.0"
2054
+ map_attribute "type", to: :type
2055
+ map_element "math", to: :math
2056
+ map_element "metadata", to: :metadata
2057
+ end
2058
+ end
2059
+
2060
+ class ExtendedUnitWithMath < Lutaml::Model::Serializable
2061
+ attribute :id, :string
2062
+ attribute :unit_symbol, ExtendedUnitSymbol
2063
+
2064
+ xml do
2065
+ root "Unit"
2066
+ namespace "https://schema.example.org/units/1.0"
2067
+ map_attribute "id", to: :id
2068
+ map_element "UnitSymbol", to: :unit_symbol
2069
+ end
2070
+ end
2071
+ ----
2072
+
2073
+ [source,ruby]
2074
+ ----
2075
+ # Create deeply nested structure with mixed namespaces
2076
+ annotation = Annotation.new(text: "Special mathematical notation", author: "Dr. Smith")
2077
+ metadata = Metadata.new(version: "2.0", annotation: annotation)
2078
+ math = MathContent.new(value: "∫f(x)dx")
2079
+ extended_symbol = ExtendedUnitSymbol.new(
2080
+ type: "Complex",
2081
+ math: math,
2082
+ metadata: metadata
2083
+ )
2084
+ extended_unit = ExtendedUnitWithMath.new(
2085
+ id: "U_complex",
2086
+ unit_symbol: extended_symbol
2087
+ )
2088
+ ----
2089
+
2090
+ Generated XML with multiple namespace levels:
2091
+
2092
+ [source,xml]
2093
+ ----
2094
+ <Unit xmlns="https://schema.example.org/units/1.0" id="U_complex">
2095
+ <UnitSymbol type="Complex">
2096
+ <math xmlns="http://www.w3.org/1998/Math/MathML">∫f(x)dx</math>
2097
+ <metadata xmlns="https://schema.example.org/metadata/1.0" version="2.0">
2098
+ <annotation xmlns="https://schema.example.org/annotation/1.0" author="Dr. Smith">
2099
+ <text>Special mathematical notation</text>
2100
+ </annotation>
2101
+ </metadata>
2102
+ </UnitSymbol>
2103
+ </Unit>
2104
+ ----
2105
+
2106
+ *Key behaviors for complex nesting:*
2107
+
2108
+ * **Level 1** (`Unit`): Units namespace declared
2109
+ * **Level 2** (`UnitSymbol`): Inherits units namespace (no xmlns)
2110
+ * **Level 3a** (`math`): Declares MathML namespace (different from parent)
2111
+ * **Level 3b** (`metadata`): Declares metadata namespace (different from parent)
2112
+ * **Level 4** (`annotation`): Declares annotation namespace (different from metadata parent)
2113
+ * **Level 5** (`text`): Inherits annotation namespace (same as parent)
2114
+
2115
+ This demonstrates how the framework:
2116
+
2117
+ 1. Tracks namespace context at each nesting level
2118
+ 2. Only declares xmlns when namespace actually changes
2119
+ 3. Maintains proper inheritance even across multiple namespace transitions
2120
+ 4. Produces clean, standards-compliant XML regardless of nesting complexity
2121
+ ====
2122
+
2123
+ === Complex nested namespace scenarios
2124
+
2125
+ ==== Multiple nesting levels with same namespace
2126
+
2127
+ For deeply nested structures where all elements share the same namespace,
2128
+ the framework optimizes by declaring the namespace only at the root level.
2129
+
2130
+ [source,ruby]
2131
+ ----
2132
+ # Given the UnitsML example above with 4 nesting levels:
2133
+ # Unit -> UnitSystem/UnitName/RootUnits -> EnumeratedRootUnit (collection)
2134
+
2135
+ unit = Unit.from_xml(xml_with_multiple_nesting)
2136
+ # All nested elements correctly inherit the namespace
2137
+ # No redundant xmlns declarations at any level
2138
+ ----
2139
+
2140
+ ==== Mixed namespaces at different nesting levels
2141
+
2142
+ When namespaces change at various nesting levels, each namespace transition
2143
+ is handled correctly with appropriate `xmlns` declarations.
2144
+
2145
+ [source,ruby]
2146
+ ----
2147
+ # Pattern:
2148
+ # - Level 1: Units namespace
2149
+ # - Level 2: Units namespace (inherited)
2150
+ # - Level 3: MathML namespace (new declaration needed)
2151
+
2152
+ # The framework automatically:
2153
+ # 1. Inherits namespace when same as parent
2154
+ # 2. Declares namespace when different from parent
2155
+ # 3. Optimizes declarations for minimal XML output
2156
+ ----
2157
+
2158
+ *Namespace inheritance rules:*
2159
+
2160
+ 1. **Same namespace as parent**: Child element inherits parent's namespace (no xmlns)
2161
+ 2. **Different namespace from parent**: Child element declares its own namespace (xmlns added)
2162
+ 3. **Root element**: Always declares its own namespace if specified
2163
+ 4. **Collections**: Each item in collection follows same inheritance rules
2164
+ 5. **Round-trip preservation**: Namespace structure preserved during serialization/deserialization
2165
+
2166
+ This approach ensures both XML correctness and optimal output size, following
2167
+ W3C XML Namespace recommendations for namespace inheritance and declaration.
@@ -0,0 +1,35 @@
1
+ = Missing XML Features in lutaml-model
2
+ :toc:
3
+ :toclevels: 2
4
+
5
+ This page summarizes major XML-related topics and specifications that are not fully supported in lutaml-model. Each section links to a dedicated reference document and provides a brief overview of the topic and its relevance.
6
+
7
+ == XML 1.0 — Core Specification
8
+ link:xml_1.0.adoc[XML 1.0 Specification]
9
+ [.description]
10
+ Provides the complete W3C specification for XML 1.0 (Fifth Edition), covering document structure, elements, attributes, entities, notations, character encoding, well-formedness, and validity rules. This is the foundational standard for all XML processing and interoperability. lutaml-model relies on XML 1.0 compliance for parsing and serialization, but does not implement all advanced features such as DTD validation, notations, or full entity management.
11
+
12
+ == XML Base (`xml:base`)
13
+ link:xml_base.adoc[XML Base Specification]
14
+ [.description]
15
+ Describes the `xml:base` attribute, which allows authors to set or override the base URI for parts of an XML document. This is essential for resolving relative URIs, supporting modular document structures, and enabling reliable linking in XML applications (such as XLink and stylesheets). The specification covers inheritance, resolution rules, encoding, security considerations, and conformance requirements. lutaml-model does not currently implement any `xml:base` logic or base URI resolution.
16
+
17
+ == XML Schema Datatypes & Facets
18
+ link:xml_data_types.adoc[XML Schema Datatypes & Facets]
19
+ [.description]
20
+ Covers XML Schema Part 2: Datatypes, including primitive types (string, integer, date, etc.) and constraining facets (length, pattern, enumeration, bounds, whitespace normalization, etc.). These facets are used to restrict and validate data in XML documents, ensuring data quality and schema compliance. The document also details which facets and datatypes are implemented or missing in lutaml-model, highlighting gaps in validation, type support, and error handling.
21
+
22
+ == XML Namespaces
23
+ link:xml_namespace.adoc[XML Namespaces Specification]
24
+ [.description]
25
+ Explains the concept of XML namespaces, which prevent naming collisions by qualifying element and attribute names with URIs. Topics include namespace declarations, reserved prefixes (`xml`, `xmlns`), QName and NCName syntax, scoping rules, validation constraints, processor responsibilities, and best practices for schema authors. The implementation status table shows which namespace features are supported or missing in lutaml-model, including reserved prefix handling and attribute uniqueness.
26
+
27
+ == XML Schema Part 1: Structures
28
+ link:xml_schema.adoc[XML Schema Part 1: Structures]
29
+ [.description]
30
+ Provides a comprehensive reference for XML Schema structures, including type definitions, element and attribute declarations, constraints, validation rules, conformance levels, and processing guidelines. This is the foundation for defining and validating the structure of XML documents, supporting interoperability and robust data modeling. The document includes an implementation checklist and a summary of which features are supported or missing in lutaml-model, such as identity constraints, annotation, and schema location rules.
31
+
32
+ == XLink 1.1 — XML Linking Language
33
+ link:xml_xlink.adoc[XLink 1.1 Specification]
34
+ [.description]
35
+ Overviews the XML Linking Language (XLink), which enables both simple and complex links between resources in XML documents. Topics include global attributes, link types (simple, extended, locator, arc, resource, title), traversal rules, linkbase processing, conformance requirements, and integration with XML Base and namespaces. lutaml-model does not currently implement any XLink features, element recognition, or validation logic.