-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
XML table should gracefully handle empty nodes/elements #122
Conversation
…e a column mapping
lib/ndr_import/xml/table.rb
Outdated
@@ -179,6 +181,12 @@ def mappable_xpaths_from(line) | |||
xpaths | |||
end | |||
|
|||
def populated_leaf?(node) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think leaf may be old naming convention?
maybe
populated?(node)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep, agreed
@@ -179,6 +181,12 @@ def mappable_xpaths_from(line) | |||
xpaths | |||
end | |||
|
|||
def populated_leaf?(node) | |||
node.element_children.empty? && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so
Given this xml, we'd expect pathology
to be blank:
<root>
<record>
<no_relative_path value="A value"/>
<no_path_or_att>Another value</no_path_or_att>
<demographics>
<demographics_1>AAA</demographics_1>
<demographics_2 code="03">Inner text</demographics_2>
<address></address>
</demographics>
<pathology></pathology>
</record>
</root>
But blank?
returns false.
[1] pry(#<NdrImport::Xml::Table>)> node
=> #(Element:0x1360 { name = "pathology" })
[2] pry(#<NdrImport::Xml::Table>)> node.blank?
=> false
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just update the name ofpopulated_leaf
method? (and subsequent method calls)
Xml::Table
checks that every xpath from an xml record is accounted for in column mappings, this means that empty nodes/sections require a column mappingExample xml:
The
pathology
section is empty, but would require a column mapping, that is set todo_not_capture
, so thatXml::Table
is happy the xpath is accounted for.column mapping for
pathology
:This PR only requires a column mapping where the section/mode/elment is populated, and would mean the above column mapping wouldn't be required