0

I have a xml (http://pastebin.com/q64L3ECX) that I need to import with Feeds module into my site. Basically, with this xml example, I need to import 3 nodes where my GUID (set as unique) is "test_case". Each test_case is inside a test_set.

The problem is that I can only get the first test_case of each of the two test_set of that file. Can someone help me understand what is wrong?

Drupal Xpath Parser Settings

Debug output:

xpathparser:0 :
<test_set_name tl_label="Name" tl_name="name" tl_physicalname="CY_CYCLE">GUI.00 Launch Applications</test_set_name>
<test_set_name tl_label="Name" tl_name="name" tl_physicalname="CY_CYCLE">GUI.02 EM NE.000 EM NE Generic.Generic EM NE tests</test_set_name>
xpathparser:1 :
<test_case_name tp_label="Test Name" tp_name="name" tp_physicalname="TS_NAME">Launch TNMS</test_case_name>
<test_case_name tp_label="Test Name" tp_name="name" tp_physicalname="TS_NAME">Open</test_case_name>
<test_case_name tp_label="Test Name" tp_name="name" tp_physicalname="TS_NAME">ManualNetworkScan</test_case_name>

Created 1 node.
8
  • You can try to use "/report/test_sets/*" Aug 22, 2015 at 11:49
  • Thanks ar7max but that doesn't solve the problem. Maybe I can't get both the test_case and the test_set?
    – zephirus
    Aug 22, 2015 at 15:11
  • I added the output of my import. The 2 test_sets and 3 test_cases are there so why only 1 node is created? If I use ar7max suggestion I get no nodes.
    – zephirus
    Aug 22, 2015 at 15:33
  • I tried changing the context to "//report/test_sets/test_set|//report/test_sets/test_set/test_cases/test_case" and now 5 nodes are created. The problem is that I need 3 nodes, 2 with one test_set and the other with the corresponding test_set.
    – zephirus
    Aug 22, 2015 at 21:54
  • The problem as I can see in relation test_set 1:n test_case Aug 22, 2015 at 21:58

1 Answer 1

1

For example, our relation's key will be test case's GUID (Test cases (Entity reference by Feeds GUID) (field_test_cases)):

  • Content type test_set:
    • field_test_cases: Type - Entity Reference, Target type - Test case (type test_case), Number of values - unlimited.
  • Content type test_case: standard Title and Body fields.

Test case's importer's config:

$feeds_importer = new stdClass();
$feeds_importer->disabled = FALSE; /* Edit this to true to make a default feeds_importer disabled initially */
$feeds_importer->api_version = 1;
$feeds_importer->id = 'test_cases';
$feeds_importer->config = array(
  'name' => 'Test cases',
  'description' => '',
  'fetcher' => array(
    'plugin_key' => 'FeedsFileFetcher',
    'config' => array(
      'allowed_extensions' => 'txt csv tsv xml opml html htm',
      'direct' => FALSE,
      'directory' => 'public://feeds',
      'allowed_schemes' => array(
        0 => 'public',
      ),
    ),
  ),
  'parser' => array(
    'plugin_key' => 'FeedsXPathParserXML',
    'config' => array(
      'sources' => array(
        'xpathparser:0' => 'text()',
        'xpathparser:1' => 'text()',
      ),
      'rawXML' => array(
        'xpathparser:0' => 0,
        'xpathparser:1' => 0,
      ),
      'context' => '/report/test_sets/test_set/test_cases/test_case/test_case_name',
      'exp' => array(
        'errors' => 0,
        'debug' => array(
          'context' => 0,
          'xpathparser:0' => 0,
          'xpathparser:1' => 0,
        ),
      ),
      'allow_override' => 1,
    ),
  ),
  'processor' => array(
    'plugin_key' => 'FeedsNodeProcessor',
    'config' => array(
      'expire' => '-1',
      'author' => 0,
      'authorize' => 1,
      'mappings' => array(
        0 => array(
          'source' => 'xpathparser:0',
          'target' => 'guid',
          'unique' => 1,
        ),
        1 => array(
          'source' => 'xpathparser:1',
          'target' => 'title',
          'unique' => 1,
        ),
      ),
      'update_existing' => '1',
      'update_non_existent' => 'skip',
      'input_format' => 'plain_text',
      'skip_hash_check' => 1,
      'bundle' => 'test_case',
    ),
  ),
  'content_type' => '',
  'update' => 0,
  'import_period' => '-1',
  'expire_period' => 3600,
  'import_on_create' => 1,
  'process_in_background' => 0,
);

Test set's importer's config:

$feeds_importer = new stdClass();
$feeds_importer->disabled = FALSE; /* Edit this to true to make a default feeds_importer disabled initially */
$feeds_importer->api_version = 1;
$feeds_importer->id = 'test_set';
$feeds_importer->config = array(
  'name' => 'Test set',
  'description' => '',
  'fetcher' => array(
    'plugin_key' => 'FeedsFileFetcher',
    'config' => array(
      'allowed_extensions' => 'txt csv tsv xml opml html htm',
      'direct' => FALSE,
      'directory' => 'public://feeds',
      'allowed_schemes' => array(
        0 => 'public',
      ),
    ),
  ),
  'parser' => array(
    'plugin_key' => 'FeedsXPathParserXML',
    'config' => array(
      'sources' => array(
        'xpathparser:0' => 'test_set_name/text()',
        'xpathparser:1' => 'test_set_name/text()',
        'xpathparser:2' => 'test_cases/test_case/test_case_name/text()',
      ),
      'rawXML' => array(
        'xpathparser:0' => 0,
        'xpathparser:1' => 0,
        'xpathparser:2' => 0,
      ),
      'context' => '/report/test_sets/test_set',
      'exp' => array(
        'errors' => 0,
        'debug' => array(
          'context' => 0,
          'xpathparser:0' => 0,
          'xpathparser:1' => 0,
          'xpathparser:2' => 0,
        ),
      ),
      'allow_override' => 1,
    ),
  ),
  'processor' => array(
    'plugin_key' => 'FeedsNodeProcessor',
    'config' => array(
      'expire' => '-1',
      'author' => 0,
      'authorize' => 1,
      'mappings' => array(
        0 => array(
          'source' => 'xpathparser:0',
          'target' => 'guid',
          'unique' => 1,
        ),
        1 => array(
          'source' => 'xpathparser:1',
          'target' => 'title',
          'unique' => 1,
        ),
        2 => array(
          'source' => 'xpathparser:2',
          'target' => 'field_test_cases',
          'unique' => FALSE,
        ),
      ),
      'update_existing' => '1',
      'update_non_existent' => 'skip',
      'input_format' => 'plain_text',
      'skip_hash_check' => 1,
      'bundle' => 'test_set',
    ),
  ),
  'content_type' => '',
  'update' => 0,
  'import_period' => '-1',
  'expire_period' => 3600,
  'import_on_create' => 1,
  'process_in_background' => 0,
);
6
  • Hi ar7max, that returns 0 nodes. The debug I get: pastebin.com/wDmdA7bT; My content type: picpaste.com/pics/Untitled-4DKRUBkw.1440366806.png (field_test_set_name allows 1 value; field_test_case_name allows unlimited as you said); My mappings in feeds: picpaste.com/pics/Untitled-Hn1LPyFD.1440366909.png
    – zephirus
    Aug 23, 2015 at 21:55
  • Very interesting, cuz was parsed right. Mb something with node processor's settings in part of updating existing nodes and mb you should try to check skip hash check Aug 23, 2015 at 22:03
  • Sorry, my bad. It worked. 2 Nodes created, 1 with one test_case. 2 with two test_cases. For this example its good but If I add more fields (test cases fields), I loose the relationship again. I really think that the best way is to do it with a custom module and have the control myself.
    – zephirus
    Aug 23, 2015 at 22:08
  • If u can provide more info about structure and your needs I will be able to try. Aug 23, 2015 at 22:17
  • Can we make a chat? If you can, it would be easier.
    – zephirus
    Aug 23, 2015 at 22:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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