Class: Xmi::Sparx::SparxRoot
- Inherits:
-
Root
- Object
- Lutaml::Model::Serializable
- Root
- Xmi::Sparx::SparxRoot
- Defined in:
- lib/xmi/sparx/root.rb
Class Method Summary collapse
-
.fix_encoding(xml_content) ⇒ String
Fix invalid UTF-8 encoding in the XML content.
-
.parse_xml(xml_content) ⇒ SparxRoot
Parse XMI content into Ruby objects.
Instance Method Summary collapse
-
#build_index ⇒ Xmi::Index
Build index for fast lookups.
-
#index ⇒ Xmi::Index
Access the index (builds on first access if needed).
Methods inherited from Lutaml::Model::Serializable
Class Method Details
.fix_encoding(xml_content) ⇒ String
Fix invalid UTF-8 encoding in the XML content.
Some EA-generated XMI files contain invalid UTF-8 byte sequences that would cause parsing failures. This method replaces invalid bytes with placeholder characters.
49 50 51 52 53 54 55 |
# File 'lib/xmi/sparx/root.rb', line 49 def fix_encoding(xml_content) return xml_content if xml_content.valid_encoding? xml_content .encode("UTF-16be", invalid: :replace, replace: "?") .encode("UTF-8") end |
.parse_xml(xml_content) ⇒ SparxRoot
Parse XMI content into Ruby objects.
This method uses automatic version detection to handle different XMI namespace versions (e.g., XMI 20110701, 20131001, 20161101) and their corresponding UML versions.
33 34 35 36 37 38 39 |
# File 'lib/xmi/sparx/root.rb', line 33 def parse_xml(xml_content) xml_content = fix_encoding(xml_content) Xmi.init_versioning! root = Xmi::VersionRegistry.parse_with_detected_version(xml_content, self) root.build_index root end |
Instance Method Details
#build_index ⇒ Xmi::Index
Build index for fast lookups
63 64 65 |
# File 'lib/xmi/sparx/root.rb', line 63 def build_index @index = Xmi::Index.new(self) end |
#index ⇒ Xmi::Index
Access the index (builds on first access if needed)
69 70 71 |
# File 'lib/xmi/sparx/root.rb', line 69 def index @index || build_index end |