We need the XML parser to skip empty items (rows). Ordinarily, empty rows would contain only empty values and be filtered out later down the chain, but we are using an XPath to a parent field (see example below) which will always contain a value. The result in our use case is that we have an incomplete row that is missing one of the values we use for a key (thereby blowing up the migration). This patch tests for an empty($target_element) instead of just testing for NULL. If there are use cases where empty items need to be processed, maybe there could be a configuration value that would allow us to skip them.

source:
  plugin: url
  data_fetcher_plugin: http
  data_parser_plugin: xml
  urls: 'http://localhost/programs.xml'
  item_selector: /root/program/Semesters_Course_List
  fields:
    -
      name: program_id
      label: Program ID
      selector: '../Program_ID'
    -
      name: courses
      label: Courses
      selector: 'Courses'
CommentFileSizeAuthor
#3 empty-xml-items-2946894-3.patch707 bytesbyrond
empty-xml-items.patch694 bytesbyrond

Comments

byrond created an issue. See original summary.

heddn’s picture

Status: Needs review » Needs work

Since we have to support BC, let's make sure to test this in a good unit test. There are some useful pointers over in #2912112: Migration failed with source plugin exception: Serialization of SimpleXMLElement is not allowed that could assist in the creation of the test. I don't want to break previously functioning users of the module while fixing this bug.

byrond’s picture

StatusFileSize
new707 bytes

The original patch I submitted wasn't fixing our issue. Here is an updated version. And, thanks @heddn! I will work on tests for this soon.