I am trying to use the D8 core migrate module to import a feed. I followed this blog so I made a .yml file. It seems though that the xpaths I am using are incorrect. The import fails:

 [error]  Migration failed with source plugin exception: guid is defined as a source ID but has no value. 

So the question is: How can I get, for example, the value of

<pro:id value="212149" />

I am aware of the namespaces, but I can't seem to figure out how to deal with them..;-(

This is (part of) the xml I am trying to parse:

<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:gd="http://schemas.google.com/g/2005" xmlns:pro="http://schemas.stager.nl/2011">
    <category scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/g/2005#event" />
    <title type="text">Stager event feed</title>
    <subtitle type="text">Events for example</subtitle>
    <generator version="1.0" uri="https://example.stager.nl/">stager</generator>
    <link rel="http://schemas.google.com/g/2005#feed" type="application/atom+xml" href="https://example.stager.nl/web/feeds/events" />
    <link rel="self" type="application/atom+xml" href="https://example.stager.nl/web/feeds/events" />
    <link rel="related" type="text/html" href="https://example.stager.nl/events/listmonth" />
    <link rel="related" type="text/calendar" href="https://example.stager.nl/web/calendar.ics" />
    <link rel="related" type="text/html" href="https://example.stager.nl/events/listweek" />
    <link rel="related" type="text/html" href="https://example.stager.nl/events/listday" />
        <pro:type value="event" />
        <pro:id value="212149" />
        <pro:eventGroupId value="213066" />
        <category scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/contact/2008#contact" />
        <title>House of bars</title>
        <pro:subtitle>Lorem Ipsum</pro:subtitle>
        <link rel="self" type="application/atom+xml" href="https://example.stager.nl/web/feeds/events/212149" />
        <link rel="alternate" type="text/html" href="https://example.stager.nl/events/212149" />
        <link rel="alternate" type="text/calendar" href="https://example.stager.nl/web/events/212149.ics" />
        <link rel="related" type="text/html" href="https://example.stager.nl/events/listday?month=5&amp;year=2018&amp;day=04" />
        <category scheme="http://schemas.stager.nl/2011#eventType" term="dancenight" label="Dancenight" />
        <pro:tags>rock, poop, </pro:tags>
        <gd:eventStatus value="http://schemas.google.com/g/2005#event.confirmed" />
        <gd:where rel="http://schemas.google.com/g/2005#event" label="example">
                    <category scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/contact/2008#contact" />
                    <gd:structuredPostalAddress primary="true">
                        <gd:street>ladida 39</gd:street>
                        <gd:postcode>0000 AA</gd:postcode>
                        <gd:formattedAddress>example, ladida 39, 0000 AA Sometown </gd:formattedAddress>
                    <summary>example, ladida 39, 0000 AA Sometown  </summary>
        <gd:when startTime="2018-05-04T22:00:00+02:00" endTime="2018-05-05T02:00:00+02:00" />
        <gd:extendedProperty name="http://schemas.stager.nl/2011#doorsOpen">
            <gd:when startTime="2018-05-04T22:00:00+02:00" />
        <pro:tickets isSoldOut="false">
        <link rel="hyperlink" href="https://www.example.net/" title="poop poop de doop" featured="false" />
        <link rel="audiolink" href="http://hcmaslov.d-real.sci-nnov.ru/public/mp3/Queen/Queen%20'A%20Kind%20Of%20Magic'.mp3" featured="false" />
        <link rel="videolink" href="https://www.youtube.com/watch?v=dQw4w9WgXcQ" featured="false" />
        <link rel="image" href="https://example.stager.nl/images/7/eventpublicationitem/320078/Screen Shot 2018-05-01 at 13.18.21.png" featured="false" />
        <content type="html">&lt;p&gt;Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer pulvinar nibh nec ante eleifend pulvinar. Nulla molestie vel justo ac faucibus. Duis consectetur eu ipsum at dictum. Suspendisse convallis hendrerit leo a molestie. Quisque sollicitudin felis velit, nec laoreet massa tincidunt et.&lt;/p&gt;&lt;p&gt;Aenean nec gravida mi, sodales hendrerit purus. Mauris gravida risus ipsum, sit amet porta tellus vehicula feugiat. Donec posuere fringilla sapien vel vestibulum. Nunc nec scelerisque ligula. Donec vitae tempus nulla, rhoncus egestas lacus. Nulla rutrum nec nulla ut ullamcorper. Ut consectetur blandit libero non eleifend. Duis ut rutrum sem. Sed dapibus lectus vel metus dictum euismod. Donec at purus vitae elit mattis consequat fringilla quis massa. Nam at velit sed lorem ultricies semper. Quisque viverra congue mi, at venenatis purus vehicula nec.&lt;/p&gt;</content>

My .yml is this:

id: stager_events_importer
label: 'Import examples Stager Atom feed'
status: true

  plugin: url
  data_fetcher_plugin: http
  data_parser_plugin: xml
      atom: 'http://www.w3.org/2005/Atom'
      gd: 'http://schemas.google.com/g/2005'
      pro: 'http://schemas.stager.nl/2011'
  urls: 'https://example.stager.nl/web/feeds/events'

  item_selector: '/feed/entry'
      name: guid
      label: GUID
      selector: '/pro:id@value'
      name: title
      label: Title
      selector: 'title'
      name: pub_date
      label: 'Publication date'
      selector: 'published'
      name: type
      label: Type
      selector: 'pro:type@value'
      name: category
      label: Category
      selector: 'category[2]@term'
      name: tags
      label: Tags
      selector: 'pro:tags'
      name: body
      label: Body
      selector: 'content'

      type: string

  plugin: 'entity:node'

  title: title
  field_type: type
  body: body
    plugin: format_date
    from_format: 'D, d M Y H:i:s O'
    to_format: 'U'
    source: pub_date
    plugin: default_value
    default_value: 1
    plugin: default_value
    default_value: event

I looked here, but I did not get it yet.

I have a contenttype 'event' with fields corresponding to the ones referenced in the process config of the yml.


Turns out it was mostly an indentation problem: the namespaces were two tabs in, instead of 1

      atom: 'http://www.w3.org/2005/Atom'
      gd: 'http://schemas.google.com/g/2005'
      pro: 'http://schemas.stager.nl/2011'

should be:

  atom: 'http://www.w3.org/2005/Atom'
  gd: 'http://schemas.google.com/g/2005'
  pro: 'http://schemas.stager.nl/2011'

Then the value of ID is:

      name: guid
      label: GUID
      selector: 'pro:id/@value'

and the title (this is catchy!, notice the 'atom:' prefix)

      name: title
      label: Title
      selector: 'atom:title'

Also this needs to be added (if, of course, there are no dependencies):

  required: {}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.