-
-
Notifications
You must be signed in to change notification settings - Fork 110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
multiple elements with different values #159
Comments
JS objects cannot have duplicate keys. You need to wrap those elements in an array. |
Hi, could you give an code example please? I tried this, but it's not working:
Output is
Thanks |
Am Donnerstag, den 25.05.2017, 13:05 -0700 schrieb Ozgur Ozcitak:
See here please:
#71 (comment)
Sorry, but still don't get it. Could you give an example please.
Thanks
marcus
|
Here is a workaround: var obj = { 'mdui:UIInfo' :
[
{ 'mdui:DisplayName': { "@xml:lang": "de", "#text": "Mein Titel" } },
{ 'mdui:DisplayName': { "@xml:lang": "en", "#text": "My title" } },
{ 'mdui:Description': { "@xml:lang": "de", "#text": "Ein Test" } },
{ 'mdui:Description': { "@xml:lang": "en", "#text": "a test" } }
]
};
xmlbuilder.create(obj, {separateArrayItems: true}); |
Ozgur! Thank you, that's working 🥇 |
Your code should also work too: 'mdui:UIInfo': {
"mdui:DisplayName": [
{ "@xml:lang": "de", "#text": "AAA" },
{ "@xml:lang": "en", "#text": "BBB" }
]
} I'll take a look. |
I'm trying to generate a moderately complicated XML, but I've hit an issue similar to this one. The solution works at the first level, but on the second level it doesn't output correctly. Here is a sample JSON object that I'm converting. The attribute groups are expanded correctly, but the nested attribute are not. I tried using both forms with each array element prefixed with 'attribute' and not. I'm trying to build a list of 'attribute' elements directly under each 'attribute-group' {
"category": {
"@category-id": "twe-root",
"display-name": {
"#text": "Root",
"@xml:lang": "x-default"
},
"description": {
"#text": "Master Catalogue for Treasury Wines",
"@xml:lang": "x-default"
},
"online-flag": {
"#text": true
},
"attribute-groups": [
{
"attribute-group": {
"@group-id": "wine",
"display-name": {
"#text": "Wine Attributes",
"@xml:lang": "x-default"
},
"attribute": [
{
"@attribute-id": "wineContentChannels",
"@system": false
},
{
"@attribute-id": "wineTastingNotesPDF",
"@system": false
},
{
"@attribute-id": "wineCOGS",
"@system": false
},
{
"@attribute-id": "wineCollection",
"@system": false
},
{
"@attribute-id": "wineType",
"@system": false
},
{
"@attribute-id": "wineVariety",
"@system": false
},
{
"@attribute-id": "wineBottleType",
"@system": false
},
{
"@attribute-id": "wineVintage",
"@system": false
}
]
}
},
{
"attribute-group": {
"@group-id": "coreProduct",
"display-name": {
"#text": "Core Product Attributes",
"@xml:lang": "x-default"
},
"attribute": [
{
"@attribute-id": "csrOnly",
"@system": false
}
]
}
}
]
}
}, |
Testing with the current master branch at d8d2447, it appears both issues are solved. @localguru with this JS object: {
'mdui:UIInfo': {
"mdui:DisplayName": [
{ "@xml:lang": "de", "#text": "AAA" }
{ "@xml:lang": "en", "#text": "BBB" }
]
}
} the output is <mdui:UIInfo>
<mdui:DisplayName xml:lang="de">AAA</mdui:DisplayName>
<mdui:DisplayName xml:lang="en">BBB</mdui:DisplayName>
</mdui:UIInfo> @rgilling with your JS object above the output is: <category category-id="twe-root">
<display-name xml:lang="x-default">Root</display-name>
<description xml:lang="x-default">Master Catalogue for Treasury Wines</description>
<online-flag>true</online-flag>
<attribute-groups>
<attribute-group group-id="wine">
<display-name xml:lang="x-default">Wine Attributes</display-name>
<attribute attribute-id="wineContentChannels" system="false"/>
<attribute attribute-id="wineTastingNotesPDF" system="false"/>
<attribute attribute-id="wineCOGS" system="false"/>
<attribute attribute-id="wineCollection" system="false"/>
<attribute attribute-id="wineType" system="false"/>
<attribute attribute-id="wineVariety" system="false"/>
<attribute attribute-id="wineBottleType" system="false"/>
<attribute attribute-id="wineVintage" system="false"/>
</attribute-group>
</attribute-groups>
<attribute-groups>
<attribute-group group-id="coreProduct">
<display-name xml:lang="x-default">Core Product Attributes</display-name>
<attribute attribute-id="csrOnly" system="false"/>
</attribute-group>
</attribute-groups>
</category> Can you please check if those are the expected results? |
@oozcitak I know this issue is closed, but a new scenario came up. How could I generate an xml with this structure?
where there are 2 paragraphs nodes, but in differents parts of the xml body. |
@littlebacklash You can do something like this (note the const obj = {
'text': {
'#text': [
{ 'paragraph': 'Symbolic text number 1' }
{ 'table': '' }
{ 'paragraph': '** Symbolic text number 2 **' }
]
}
} |
Hi,
for a shibb IdP I'd like to generate something like this:
My js code:
This code ends up in just one element of DisplayName and Description
Any ideas?
Ciao!
The text was updated successfully, but these errors were encountered: