XML parsing, return all elements except _children dynamically

Hi

this code is
CALL apoc.load.xml ($mirror_filelocation, '')
YIELD value
UNWIND value._children AS plmxml
with plmxml
where plmxml._type = "ProductView"
with plmxml
return plmxml

returning a json like this. I want to return a map of all attributes except under _children dynamically without mentioning the name of attributes in my cypher.
i want to return
{
"primaryOccurrenceRef": "id10",
"_type": "ProductView",
"id": "id4",
"ruleRefs": "#id2",
"rootRefs": "id7"
}

how can i do it ?

the retuned json from above stmt is in below.

Thanks

{
"_children": [
{
"_type": "ApplicationRef",
"label": "xDVplLIJqd$DyB/QkqRC5OMJ6JDmB/AAAAAAAAAAAAAA/BOM/"
},
{
"_type": "UserData",
"_children": [
{
"_type": "UserValue",
"title": "BOM_precision_type",
"value": "imprecise"
}
],
"primaryOccurrenceRef": "id10",
"_type": "ProductView",
"id": "id4",
"ruleRefs": "#id2",
"rootRefs": "id7"
}

You can try using apoc.map.clean to remove the "_children" attribute, leaving all the remaining ones.

thank you Gary

apoc.map.clean is working but it is a function
i need to create a merge statment with remaining keys that are putput of apoc.map.clean.
how can i continue below to create a node at the end.

i have like this now
CALL apoc.load.xml ($mirror_filelocation, '')
YIELD value
UNWIND value._children AS plmxml
with plmxml
where plmxml._type = "ProductView"
with plmxml
return apoc.map.clean( plmxml , ["_children"], [""]) as output

output is returning this
{
"_type": "ProductView",
"id": "id4",
"ruleRefs": "#id2",
"primaryOccurrenceRef": "id10",
"rootRefs": "id7"
}

if i want to create a node with type that is value of output._type and also have attributes of the nodes exactly the same as keys mentioned in output, how i do it without hardcoding ?

Thanks a lot

CALL apoc.load.xml ($mirror_filelocation, '')
YIELD value
UNWIND value._children AS plmxml
with plmxml
where plmxml._type = "ProductView"
with plmxml._type as label,  apoc.map.clean( plmxml , ["_children"," _type"], [""]) as properties
Return apoc.create.node([label], properties)

In this case you could replace '[label]' with '["ProductView"]' in this case, since plmxml._type always equals "ProductView". I left it generic incase you expand the 'where' condition to add extra types.

Thank you Gary, you are shaping the work nicely

assume executing your code, it creates many, nodes, all labeled : Occurrence. example of three nodes are in here.

the nodes have properties : id and occurrenceRefs. for example occurrenceRefs = "id93 id206"
those two ids in OccurenceRefs are child nodes of this node. it can be 0,1 or many childs mentioned in OccurenceRefs

for every node, i have two parse occurenceRefs to get those ids ( space separated, ) and then find associated nodes with those ids and create a CHILD relationship.

is there apocs to parse occurenceRefs to create a list and then how to do a for loop for all of those IDs in the list to do match and then create relationships?

match ( o:Occurrence) return o

{
"identity": 49,
"labels": [
"Occurrence"
],
"properties": {
"instanceRefs": "#id297",
"associatedAttachmentRefs": "#id78 #id86",
"occurrenceRefs": "id93 id206",
"_type": "Occurrence",
"instancedRef": "#id289",
"id": "id7",
"sourceRef": "#id288",
"parentRef": "#id42"
},
"elementId": "49"
}

{
"identity": 52,
"labels": [
"Occurrence"
],
"properties": {
"instanceRefs": "#id200",
"associatedAttachmentRefs": "#id97 #id104",
"occurrenceRefs": "id111 id151",
"_type": "Occurrence",
"instancedRef": "#id192",
"id": "id93",
"sourceRef": "#id191",
"parentRef": "#id7"
},
"elementId": "52"
}

{
"identity": 55,
"labels": [
"Occurrence"
],
"properties": {
"instanceRefs": "#id284",
"associatedAttachmentRefs": "#id210 #id217",
"occurrenceRefs": "id224 id239",
"_type": "Occurrence",
"instancedRef": "#id276",
"id": "id206",
"sourceRef": "#id275",
"parentRef": "#id7"
},
"elementId": "55"
}

while waiting for your help, i found i can split "id93 id206" to a list using
match ( o:Occurrence) return o, apoc.text.split( o.occurrenceRefs, " ") as splt

now i have two create relationship between the parent and two children in this list . somehow i have to iterate through elements in the list to repeat an action

it will be great you can help me.

thanks a lot

That is odd that you are getting 'Occurrence' nodes, when the condition is to filter through only 'ProductView' types. I assumed you changed that condition in your query.

Cypher has its own 'split' function. I used in the following query. The query extracts the id's, matches to find the corresponding Occurrence node, then creates a relationship between each Occurrence node and its parent node.

Let me know if it doesn't work.

CALL apoc.load.xml ($mirror_filelocation, '')
YIELD value
UNWIND value._children AS plmxml
with plmxml
where plmxml._type = "Occurrence"
with plmxml._type as label,  apoc.map.clean( plmxml , ["_children"," _type"], [""]) as properties
WITH apoc.create.node([label], properties) as node, split(properties['occurrenceRefs'], " ") as child_ids
UNWIND child_ids as id
match (o:Occurrence{id:id})
merge(node)-[r:HAS_CHILD]->(o)
set node.occurrenceRefs = null
return node, o, r