Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
11-30-2021 12:58 AM
Here is the structure of xml file:
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.
How can I create 2 different labels for Product and product Revision and create a relationship (Product)-[has_this_revision]-[ProductRevision] ?
Solved! Go to Solution.
12-01-2021 01:10 AM
@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})
12-01-2021 01:10 AM
@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})
All the sessions of the conference are now available online