Make XmlDeclaration a ProcessingInstruction
This allows Oga to parse documents that contain an XML declaration at a place other than at the document root. Oga still only assigns the XML declaration to the document whenever it is at the top-level. This matches libxml/XML specification behaviour as far as I can tell.
This commit is contained in:
6 files changed
+65
-20
No files matched your search
+1
-1
@@ -35,8 +35,8 @@ require 'oga/xml/character_node'
|
||||
require 'oga/xml/text'
|
||||
require 'oga/xml/comment'
|
||||
require 'oga/xml/cdata'
|
||||
require 'oga/xml/xml_declaration'
|
||||
require 'oga/xml/processing_instruction'
|
||||
require 'oga/xml/xml_declaration'
|
||||
require 'oga/xml/doctype'
|
||||
require 'oga/xml/namespace'
|
||||
require 'oga/xml/default_namespace'
|
||||
|
||||
@@ -48,12 +48,14 @@ module Oga
|
||||
callback = :on_comment
|
||||
when Oga::XML::Attribute
|
||||
callback = :on_attribute
|
||||
when Oga::XML::XmlDeclaration
|
||||
# This must come before ProcessingInstruction since XmlDeclaration
|
||||
# extends ProcessingInstruction.
|
||||
callback = :on_xml_declaration
|
||||
when Oga::XML::ProcessingInstruction
|
||||
callback = :on_processing_instruction
|
||||
when Oga::XML::Doctype
|
||||
callback = :on_doctype
|
||||
when Oga::XML::XmlDeclaration
|
||||
callback = :on_xml_declaration
|
||||
when Oga::XML::Document
|
||||
callback = :on_document
|
||||
children = true
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
module Oga
|
||||
module XML
|
||||
# Class containing information about an XML declaration tag.
|
||||
class XmlDeclaration
|
||||
include ToXML
|
||||
|
||||
class XmlDeclaration < ProcessingInstruction
|
||||
# @return [String]
|
||||
attr_accessor :version
|
||||
|
||||
@@ -20,9 +18,12 @@ module Oga
|
||||
# @option options [String] :encoding
|
||||
# @option options [String] :standalone
|
||||
def initialize(options = {})
|
||||
super
|
||||
|
||||
@version = options[:version] || '1.0'
|
||||
@encoding = options[:encoding] || 'UTF-8'
|
||||
@standalone = options[:standalone]
|
||||
@name = 'xml'
|
||||
end
|
||||
|
||||
# @return [String]
|
||||
|
||||
Reference in new issue
Block a user