Skip to content
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

Merged
merged 2 commits into from
Mar 7, 2024

Conversation

ollietulloch
Copy link
Contributor

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 mapping

Example xml:

<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>
    </demographics>
    <pathology></pathology>
  </record>
</root>

The pathology section is empty, but would require a column mapping, that is set to do_not_capture, so that Xml::Table is happy the xpath is accounted for.

column mapping for pathology:

{ 'column' => 'pathology', 'klass' => 'SomeTestKlass',
   'xml_cell' => { 'relative_path' => '' },
   ' do_not_capture' => true }

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

@@ -179,6 +181,12 @@ def mappable_xpaths_from(line)
xpaths
end

def populated_leaf?(node)
Copy link
Contributor

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)

Copy link
Contributor Author

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? &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

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

Copy link
Contributor

@kenny-lee-1 kenny-lee-1 left a 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)

@ollietulloch ollietulloch merged commit 2bc8c3b into main Mar 7, 2024
9 checks passed
@ollietulloch ollietulloch deleted the feature/handle_empty_xml_nodes branch March 7, 2024 11:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants