Closed gmella closed 6 years ago
Here is what I did (but, it treats only first record):
input:
"<records><record><element><name>e1</name><value>va1</value></element><element><name>e2</name><value>va2</value></element></record><record><element><name>e2</name><value>vb2</value></element><element><name>e1</name><value>vb1</value></element></record></records>"
jbj stylesheet:
{
"$elements": {
"parseXML" : {
"specialChar": "#",
"longTag" : true
},
"select": ".element"
},
"$res": {
"get": "elements",
"foreach": {
"get": "0",
"$key": {
"select": ".name .#text",
"get": "0"
},
"$val": {
"select": ".value .#text",
"get": "0"
},
"mask": "key,val"
},
"array2object": ["key", "val"]
},
"mask": "res"
}
output:
{
"res": {
"e1": "va1",
"e2": "vb2"
}
}
Maybe you can start from there to yield all records (don't forget JBJ playground)?
Maybe this stylesheeet is clearer (at least, it's shorter):
{
"parseXML" : {
"specialChar": "#",
"longTag" : true
},
"select": ".element",
"foreach": {
"get": "0",
"$key": {
"select": ".name .#text",
"get": "0"
},
"$val": {
"select": ".value .#text",
"get": "0"
},
"mask": "key,val"
},
"array2object": ["key", "val"]
}
Yes I tried the nice JBJ ! But my knowledge is not json/js oriented. I hope that lodex get quite the same conventions ;) Thank you for your help.
Oh, here is a better solution:
{
"parseXML" : {
"specialChar": "#",
"longTag" : true
},
"foreach": {
"select": ".element",
"foreach": {
"get": "0",
"$key": {
"select": ".name .#text",
"get": "0"
},
"$val": {
"select": ".value .#text",
"get": "0"
},
"mask": "key,val"
},
" array2object": ["key", "val"]
}
}
gives:
{
"records": [
{
"key": "e1",
"val": "va1"
},
{
"key": "e2",
"val": "vb2"
}
]
}
How can man injest $e1 and $e2 in the database according following xml shape ?
I did not manage to find the proper jbj expression.
Regards, Guillaume