Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
07-04-2022 09:40 PM
Hello,
I have some XML-Files and I'm trying to get some values from it and put it on new Nodes.
Part of my Code:
call apoc.load.xml("file:///NCT0017xxxx/NCT00170157.xml") yield value
with value._children as root
......
with [x in title where x._type = 'title'][0] as title,
[x in nctid where x._type = 'nct_id'][0] as nctid,
[x in milestone where x._type = 'title'][0] as mstitle,
[x in milestone where x._type = 'participants_list'][0]._children as participantslist
with [x in title where x._type = 'title'][0] as title,
[x in nctid where x._type = 'nct_id'][0] as nctid,
[x in mstitle where x._type = 'title'][0] as mstitle,
[x in participantslist where x._type = 'participants'][0] as participants
........
Now I have the issue, that some level have multiple fields and I can only get one of those ([0] = first ).
One solution would be to unwind a range(start,max), but I dont know how to find out the value: maximum of each lvl on an xml-file. Thx for your help.
07-05-2022 08:24 PM
'participantslist' will be a list of the participants. You can get the number of participants in the list with 'size(participantslist)'. A single 'participant' should look something like:
{_type:"participants", group_id:'P1', count:'54'},
so the list 'participantslist' should look like:
[{_type:"participants", group_id:'P1', count:'54'}, {_type:"participants", group_id:'P2', count:'58'}]
What information do you want from the list? You can use list comprehension to extract the group_ids, such as:
[x in participantslist | x.group_id]
07-06-2022 07:36 PM - edited 07-06-2022 07:45 PM
The list comprehension worked well, so I tried this:
....
`String("54")` is not a collection or a map. Element access is only possible by performing a collection lookup using an integer index, or by performing a map lookup using a string key (found: String("54")[Long(0)])
07-06-2022 08:35 PM
The first one combined with the counter also doesnt work:
`String("P1")` is not a collection or a map. Element access is only possible by performing a collection lookup using an integer index, or by performing a map lookup using a string key (found: String("P1")[Long(0)])
07-07-2022 06:33 AM
Yes, the double 'unwind' will do that. For illustration purpose, the following query gives the results below. The reason is the first unwind gives you each value of the first list with the entire second list appended to each element. When you unwind the second list, it is done for each row, which represents a different value of the first list, thus you cross product of both lists.
with ['a', 'b'] as list1, ['c', 'd'] as list2
unwind list1 as itemFromList1
unwind list2 as itemFromList2
return itemFromList1, itemFromList2
it is getting a little complicated following the code without having access to the xml and your full query, but I can make this suggestion. Instead of extracting the 'group_id' values into its own list and the 'count' values into its own list, you can process the each pair of 'group_id' and 'count' together.
Assuming 'participantslist' looks like the following:
[{_type:"participants", group_id:'P1', count:'54'}, {_type:"participants", group_id:'P2', count:'58'}]
you could do something like the following:
forEach(x in participantslist |
MERGE(pa:Participants{group_id: x.group_id, count: x.count})
)
BTW- when you did this 'unwind range(0,size(participantslist)) as counters ', you will need to set the max range to size(participantslist)-1.
07-07-2022 06:51 PM - edited 07-07-2022 06:52 PM
Thank you for your advice, I am a step forward, but how can I use the variable "pa", to use it?
My plan was:
This code gave me back an empty Participants-Node, so it does not merge well :
07-08-2022 08:16 AM
It would be best to help if you provided the entire query and relevant xml.
Anyways, to address your specific issue, you can try using this snippet of cypher:
MERGE(m:M_Label{id: 3})
MERGE(p:P_Label{id: 4})
MERGE(m)-[:IN]->(p)
forEach(x in participantslist |
MERGE(pa:Participants{group_id: x.group_id, count: x.count})
MERGE (pa)-[:IN]->(m)
)
Replace the 'merge' on 'm' and 'p' with your specific node requirements.
07-08-2022 08:10 PM
This is good, it worked like I wanted. Now I have to do this for all the values. Overall my plan is it to "traverse" the file and create Nodes/Properties, but not with every value. For example I dont want the milestonelist as a Node, BUT I need all the milestonelists to get through all the data, so I am working on smt like this, with the index:
I have a link to the file as you asked for:
07-08-2022 08:13 PM - edited 07-08-2022 08:14 PM
07-09-2022 05:09 AM
Thank you...seeing the xml makes it easier.
Well, I don't think you need process the milestone_list with an index and a forEach loop. The milestone_list, once extracted, should contain a list of _children, which are the individual milestones. Thus, milestone_list._children will be a list of milestones. You can use the forEach loop on this list directly.
with milestone_list._children as milestones
forEach(i in milestones |
//process each milestone
)
07-09-2022 08:45 PM - edited 07-09-2022 09:20 PM
It is not possible to do "milestone_list._children" , because of a type missmatch (expected a map, but was list) .
All the sessions of the conference are now available online