Score:-1

How can I import data from XML into a content type using the Migrate module?

za flag

I have activated the Migrate, the Migrate Plus, and the Migrate Tools modules. I have then imported a migration file at /admin/config/development/configuration/single/import.

id: beetween_jobs
label: 'Migrate beetween jobs from XML file'
migration_group: default
source:
  plugin: xml
  data_fetcher_plugin: http
    # 'simple_xml' is configured to be able to use the 'http' fetcher.
    data_parser_plugin: simple_xml
    urls:
      - https://mywebsite/beetween.xml
    item_selector: /root/jobs
process:
  title: title
  field_diffusion: diffusion
  field_faculty : faculty
destination:
  plugin: 'entity:node'
  default_bundle: job
migration_dependencies:
  required: {  }
  optional: {  }

I could not find any official documentation, so I created that file basing on a tutorial.

On /admin/structure/migrate/manage/default/migrations, it doesn't list the migration I added. I just says:

Il n'y a pas encore de Entités migration.

Échec de connexion au serveur de base de données. Le serveur a renvoyé le message suivant : No database connection configured for source plugin variable.

Est-ce que le serveur de base de données fonctionne ?
Est-ce que la base de données existe et avez-vous saisi le bon nom de base ?
Avez vous saisi les bons nom d'utilisateur et mot de passe ?
Avez vous saisi le bon nom d'hôte de la base de données ?

sonfd avatar
in flag
For a start, I believe all of the keys under source need to be indented the same, i.e. they are all direct children of source.
sonfd avatar
in flag
While the second part of the error message talks about a database connection, I believe it can't connect to the migration source (which I believe is because it's indented improperly in your yml).
Kevin avatar
in flag
Pretty sure the migrate plus module has an examples folder that demonstrates some of this.
Score:0
za flag

As Kevin suggested, inspired by the

migrate_plus.migration.wine_role_xml.yml

file from the migrate_plus module , i have managed to make it working as such:

id: beetween_jobs
label: 'Migrate beetween jobs from XML file'
migration_group: default
source:
  # We use the XML data parser plugin.
  plugin: url
  data_fetcher_plugin: http
  data_parser_plugin: xml
  # Normally, this is one or more fully-qualified URLs or file paths. Because
  # we can't hardcode your local URL, we provide a relative path here which
  # hook_install() will rewrite to a full URL for the current site.
  urls:
    - https://my_website/files/ressources_docs/beetween.xml
  # Visit the URL above (relative to your site root) and look at it. You can see
  # that <response> is the outer element, and each item we want to import is a
  # <position> element. The item_xpath value is the xpath to use to query the
  # desired elements.
  item_selector: /root/job
  # Under 'fields', we list the data items to be imported. The first level keys
  # are the source field names we want to populate (the names to be used as
  # sources in the process configuration below). For each field we're importing,
  # we provide a label (optional - this is for display in migration tools) and
  # an xpath for retrieving that value. It's important to note that this xpath
  # is relative to the elements retrieved by item_xpath.
  fields:
    -
      name: title
      label: 'title'
      selector: title
    -
      name: diffusion
      label: 'diffusion'
      selector: diffusion
  # Under 'ids', we identify source fields populated above which will uniquely
  # identify each imported item. The 'type' makes sure the migration map table
  # uses the proper schema type for stored the IDs.
  ids:
    title:
      type: string
process:
  # Note that the source field names here (machine_name and friendly_name) were
  # defined by the 'fields' configuration for the source plugin above.
  title: title
  field_diffusion: diffusion
destination:
  plugin: 'entity:node'
  default_bundle: job
migration_dependencies:
  required: {  }
  optional: {  }
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.