appengine bulkdownloader to xml with nested entities

空扰寡人 提交于 2020-01-01 17:07:47

问题


I've got an appengine app with two simple kinds of entities - ParentEntitys and ChildEntitys. Each ParentEntity has a List of owned ChildEntitys.

@PersistenceCapable
public class ParentEntity
{
    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Key key;

    @Persistent
    private String name;

    @Persistent(defaultFetchGroup=true)
    private List<ChildEntity> children;

...

With ChildEntity similarly defined.

Now, I want to download all of my data from the datastore using the technique described at http://bulkloadersample.appspot.com/ . In their example they manage to export data to an xml file with owned entities nested inside parent entities. But when I try to use the following configuration (which very closely resembles theirs - see http://bulkloadersample.appspot.com/showfile/bulkloader_visitactivity.yaml and look at the activities property), I'm met with errors.

- kind: ParentEntity
  connector: simplexml
  connector_options:
    xpath_to_nodes: /Parents/ParentEntity
    style: element_centric

  property_map:
    - property: __key__
      external_name: key
      export_transform: transform.key_id_or_name_as_string

    - property: children
      external_name: Children
      import_transform:
        transform.list_from_child_node('Children/ChildEntity')
      export_transform:
        transform.child_node_from_list('ChildEntity')


- kind: ChildEntity
  connector: simplexml
  connector_options:
    xpath_to_nodes: /Children/ChildEntity
    style: element_centric

  property_map:
    - property: __key__
      external_name: key
      export_transform: transform.key_id_or_name_as_string

I get the following error:

google.appengine.ext.bulkload.bulkloader_errors.ErrorOnTransform: Error on trans
form. Property: children External Name: Children. Code: transform.ch
ild_node_from_list('ChildEntity') Details: 'NoneType' object is not iterable

Big update:

I've created this sample app that you can actually view and download and test

at http://rileylark.appspot.com

You can see the output I WANT at http://rileylark.appspot.com/view

Download the eclipse project to see how it works.

What I want for my 500 points is a working config.yaml file that can export the data for Parent and ChildEntities into nested XML with appcfg.py download_data


回答1:


Try using:

transform.list_from_child_node('GradingPeriods/GradingPeriod', suppress_blank=True)


来源:https://stackoverflow.com/questions/4231153/appengine-bulkdownloader-to-xml-with-nested-entities

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!