Class: DS::Manifest::SimpleXmlIdValidator
- Inherits:
-
BaseIdValidator
- Object
- BaseIdValidator
- DS::Manifest::SimpleXmlIdValidator
- Defined in:
- lib/ds/manifest/simple_xml_id_validator.rb
Instance Attribute Summary collapse
-
#namespaces ⇒ Object
Returns the value of attribute namespaces.
Attributes inherited from BaseIdValidator
Instance Method Summary collapse
-
#initialize(source, namespaces = {}) ⇒ SimpleXmlIdValidator
constructor
A new instance of SimpleXmlIdValidator.
-
#locate_record(source_path, id, id_location) ⇒ Nokogiri::XML::NodeSet
Locates a record in the XML document based on the given source path, ID, and ID location.
- #try_locate_record(xml, xpath, namespaces: nil) ⇒ Object
Methods inherited from BaseIdValidator
#add_error, #handle_count_error, #valid?
Constructor Details
#initialize(source, namespaces = {}) ⇒ SimpleXmlIdValidator
Returns a new instance of SimpleXmlIdValidator.
9 10 11 12 |
# File 'lib/ds/manifest/simple_xml_id_validator.rb', line 9 def initialize source, namespaces = {} @namespaces = namespaces.present? ? namespaces : DS::Constants::XML_NAMESPACES super source end |
Instance Attribute Details
#namespaces ⇒ Object
Returns the value of attribute namespaces.
7 8 9 |
# File 'lib/ds/manifest/simple_xml_id_validator.rb', line 7 def namespaces @namespaces end |
Instance Method Details
#locate_record(source_path, id, id_location) ⇒ Nokogiri::XML::NodeSet
Locates a record in the XML document based on the given source path, ID, and ID location.
id_location should be a template XPath expression that
returns one or more records, for example:
"//record[controlfield[@tag='001'] = 'ID_PLACEHOLDER']"
The string 'ID_PLACEHOLDER' must be in the template.It will be replaced with the ID of the record to locate.
28 29 30 31 32 |
# File 'lib/ds/manifest/simple_xml_id_validator.rb', line 28 def locate_record source_path, id, id_location locator = DS::Extractor::XmlRecordLocator.new namespaces: namespaces xml = source.load_source source_path locator.locate_record xml, id, id_location end |
#try_locate_record(xml, xpath, namespaces: nil) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/ds/manifest/simple_xml_id_validator.rb', line 34 def try_locate_record xml, xpath, namespaces: nil xml.xpath xpath, namespaces rescue Nokogiri::XML::XPath::SyntaxError => e raise unless e. =~ /undefined namespace prefix/i [] end |