Finding nodes based on criteria matching with list of maps that have different structures

The code in below

CALL apoc.load.xml ($filelocation, '')
YIELD value
UNWIND value._children AS plmxml
with plmxml 
where  plmxml._type  in [ "Header" , "ProductView"] 
with plmxml
WITH   apoc.map.clean(    plmxml ,    ["_children"],    [""]) as PV
return PV

generates this two maps. as you see the attributes are different between maps depending on "_type"

{
  "_type": "Header",
  "id": "id1",
  "transferContext": "ConfiguredDataFilesExportDefault",
  "traverseRootRefs": "#id7"
}

{
  "_type": "ProductView",
  "id": "id4",
  "ruleRefs": "#id2",
  "primaryOccurrenceRef": "id7",
  "rootRefs": "id7"
}

i want to find all nodes in DB with label as Header matched with map above on ( "_type:"Header" and id = "id1")
I want to do the same for ProductView node
after finding above two nodes then create a relationship type "master" between two nodes found

what is optimal way to write this query ?

thanks a lot

Hello @shsamardar :slight_smile:

CALL apoc.load.xml($filelocation, '') 
YIELD value 
UNWIND value._children AS plmxml
WITH plmxml 
WHERE plmxml._type IN [ "Header" , "ProductView"] 
WITH plmxml
WITH apoc.map.clean(plmxml , ["_children"], [""]) AS PV 
CALL apoc.cypher.run("MATCH (n:"+PV._type+") WHERE n.id = $id RETURN n", {id: PV.id}) 
YIELD value 
RETURN value.n AS node

Best regards,
Cobra

1 Like