Class: Xsdvi::XsdHandler
- Inherits:
-
Object
- Object
- Xsdvi::XsdHandler
- Defined in:
- lib/xsdvi/xsd_handler.rb
Overview
Handles XSD parsing and tree building
Constant Summary collapse
- XSD_NAMESPACE =
"http://www.w3.org/2001/XMLSchema"
Instance Attribute Summary collapse
-
#builder ⇒ Object
readonly
Returns the value of attribute builder.
-
#one_node_only ⇒ Object
Returns the value of attribute one_node_only.
-
#root_node_name ⇒ Object
Returns the value of attribute root_node_name.
-
#schema_namespace ⇒ Object
readonly
Returns the value of attribute schema_namespace.
Instance Method Summary collapse
- #get_elements_names(doc) ⇒ Object
-
#initialize(builder) ⇒ XsdHandler
constructor
A new instance of XsdHandler.
- #process_file(file_path) ⇒ Object
- #process_model(doc) ⇒ Object
- #set_schema_namespace(doc, element_name) ⇒ Object
Constructor Details
#initialize(builder) ⇒ XsdHandler
Returns a new instance of XsdHandler.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/xsdvi/xsd_handler.rb', line 14 def initialize(builder) @builder = builder @stack = [] @root_node_name = nil @one_node_only = false @schema_namespace = nil # Type registries for resolution (Phase 1) @complex_types = {} # QName => complexType node @simple_types = {} # QName => simpleType node @model_groups = {} # QName => group node @attribute_groups = {} # QName => attributeGroup node @elements = {} # QName => element node (for refs) # Type extension/restriction chain tracking (prevents stack overflow) @type_depth = 0 @type_ancestors = Set.new end |
Instance Attribute Details
#builder ⇒ Object (readonly)
Returns the value of attribute builder.
12 13 14 |
# File 'lib/xsdvi/xsd_handler.rb', line 12 def builder @builder end |
#one_node_only ⇒ Object
Returns the value of attribute one_node_only.
11 12 13 |
# File 'lib/xsdvi/xsd_handler.rb', line 11 def one_node_only @one_node_only end |
#root_node_name ⇒ Object
Returns the value of attribute root_node_name.
11 12 13 |
# File 'lib/xsdvi/xsd_handler.rb', line 11 def root_node_name @root_node_name end |
#schema_namespace ⇒ Object (readonly)
Returns the value of attribute schema_namespace.
12 13 14 |
# File 'lib/xsdvi/xsd_handler.rb', line 12 def schema_namespace @schema_namespace end |
Instance Method Details
#get_elements_names(doc) ⇒ Object
64 65 66 67 |
# File 'lib/xsdvi/xsd_handler.rb', line 64 def get_elements_names(doc) elements = doc.xpath("//xs:schema/xs:element", "xs" => XSD_NAMESPACE) elements.filter_map { |elem| elem["name"] } end |
#process_file(file_path) ⇒ Object
33 34 35 36 |
# File 'lib/xsdvi/xsd_handler.rb', line 33 def process_file(file_path) doc = Nokogiri::XML(File.read(file_path)) process_model(doc) end |
#process_model(doc) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/xsdvi/xsd_handler.rb', line 38 def process_model(doc) return unless doc # Extract target namespace schema_node = doc.at_xpath("/xs:schema", "xs" => XSD_NAMESPACE) @schema_namespace = schema_node["targetNamespace"] if schema_node # Phase 1: Collect all type definitions, groups, and elements collect_type_definitions(doc) collect_group_definitions(doc) collect_attribute_group_definitions(doc) collect_element_definitions(doc) # Create schema symbol when no root node specified (matches Java line 65-68) if root_node_name.nil? symbol = SVG::Symbols::Schema.new builder.set_root(symbol) end # Phase 2: Process elements with type resolution process_element_declarations(doc) # Level up after processing all elements (matches Java line 71-73) builder.level_up if root_node_name.nil? end |
#set_schema_namespace(doc, element_name) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/xsdvi/xsd_handler.rb', line 69 def set_schema_namespace(doc, element_name) elements = doc.xpath("//xs:schema/xs:element", "xs" => XSD_NAMESPACE) elements.each do |elem| if elem["name"] == element_name @schema_namespace = schema_node = doc.at_xpath("/xs:schema", "xs" => XSD_NAMESPACE) @schema_namespace = schema_node["targetNamespace"] if schema_node break end end end |