cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

How to create different labels from children values

Here is the structure of xml file:
3X_b_f_bf60c905c7d5ec7eccb576eaccc15335fbd95800.png
3X_d_b_db7fdcd7600628889928dc7a4e4cdcf46e0f48e5.png

I am trying to create 2 different labels for the children Product and Product Revision. But, I am getting all the children values in 1 single column, when I am unwinding the values.

3X_8_6_865977034b5798637b234618d6bf696e61ecca55.png

How can I create 2 different labels for Product and product Revision and create a relationship (Product)-[has_this_revision]-[ProductRevision] ?

1 ACCEPTED SOLUTION

@mahinshah.k.nazar
I didn't understand completely the xml structure, I think is similar to this one:

<?xml version="1.0"?>
<catalog>
  <product>
    <id>123</id>
    <description>...........</description>
 </product>
   <product>
     <id>456</id>
     <description>....</description>
  </product>
   <productRevision>
     <id>999</id>
     <description>.....</description>
   </productRevision>
   <productRevision>
     <id>888</id>
     <description>.....</description>
  </productRevision>
</catalog>

With this structure, you could do something like this:

call apoc.load.xml('file:/books.xml') yield value as catalog
with catalog._children as children
with children, [item in children WHERE item._type = "product"] AS products
with children, products, [item in children WHERE item._type = "productRevision"] AS productsRev

unwind range(0, size(products) - 1) as index // create list from 0 to size products - 1

with products[index] as prod, productsRev[index] as prodRev // splitted prod and product revision - do something else if necessary

with prod._children as prodChild, prodRev._children as prodRevChild 
with prodChild, prodRevChild, [item in prodChild WHERE item._type = "id"][0] AS idProd // get id tag product
with idProd, prodChild, prodRevChild, [item in prodRevChild WHERE item._type = "id"][0] AS idProductRev // get id tag product rev

with idProd._text as idProdText, idProductRev._text as idProductRevText // get id tag content
merge (:Product {id: idProdText})-[:has_this_revision]->(:ProductRevision {id: idProductRevText})

View solution in original post

2 REPLIES 2

@mahinshah.k.nazar
I didn't understand completely the xml structure, I think is similar to this one:

<?xml version="1.0"?>
<catalog>
  <product>
    <id>123</id>
    <description>...........</description>
 </product>
   <product>
     <id>456</id>
     <description>....</description>
  </product>
   <productRevision>
     <id>999</id>
     <description>.....</description>
   </productRevision>
   <productRevision>
     <id>888</id>
     <description>.....</description>
  </productRevision>
</catalog>

With this structure, you could do something like this:

call apoc.load.xml('file:/books.xml') yield value as catalog
with catalog._children as children
with children, [item in children WHERE item._type = "product"] AS products
with children, products, [item in children WHERE item._type = "productRevision"] AS productsRev

unwind range(0, size(products) - 1) as index // create list from 0 to size products - 1

with products[index] as prod, productsRev[index] as prodRev // splitted prod and product revision - do something else if necessary

with prod._children as prodChild, prodRev._children as prodRevChild 
with prodChild, prodRevChild, [item in prodChild WHERE item._type = "id"][0] AS idProd // get id tag product
with idProd, prodChild, prodRevChild, [item in prodRevChild WHERE item._type = "id"][0] AS idProductRev // get id tag product rev

with idProd._text as idProdText, idProductRev._text as idProductRevText // get id tag content
merge (:Product {id: idProdText})-[:has_this_revision]->(:ProductRevision {id: idProductRevText})