-
-
Notifications
You must be signed in to change notification settings - Fork 21
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
tag with attributes not working #52
Comments
I tried this reduced test case and it seemed to work as expected: toXML({
_name: 'Amt',
_attrs: { Ccy: 'EUR' },
_content: 158.4
});
// -> <Amt Ccy="EUR">158.4</Amt> Maybe something else is going on? What happens if you |
Hi, thanks for the reply. Just before you posted it, I left for the day, so I couodnt verify, but let me give blind programming a go I think where the misunderstanding comes from is that you did the test case in a reduced fashion. What if you wrapped the Amt tag inside another element, such as
What I want to happen |
A good way to think of this is that toXML({
Element: [
{
_name: 'Amt',
_attrs: { Ccy:'EUR' },
_content: "158.4"
},
{
ChildElement: 'ChildValue'
}
]
});
// -> <Element><Amt Ccy="EUR">158.4</Amt><ChildElement>ChildValue</ChildElement></Element> This also works if you prefer consistency: toXML({
Element: [
{
_name: 'Amt',
_attrs: { Ccy:'EUR' },
_content: "158.4"
},
{
_name: 'ChildElement',
_content: "ChildValue"
}
]
});
// -> <Element><Amt Ccy="EUR">158.4</Amt><ChildElement>ChildValue</ChildElement></Element> |
Indeed It is. Might I suggest updating the examples (maybe number 2, because array syntax is not needed only for duplicate keys, but also for multiple child nodes, which can very well be distinct. I have re-read the examples and the only one this idea comes out on is example number 9 & 10 (and maybe 16 as well, although not mentioned directly) |
Either way, thank you and closing this out |
I am trying to generate
<Amt Ccy="EUR">158.4</Amt>
(as part of a larger SEPA payment xml)Following the examples 4 and 7, I came up with
this.creditTransferTxXml.CdtTrfTxInf.Amt = {_attrs: {Ccy:SEPAInfo.payment.currency}, _content: SEPAInfo.payment.amount.toString()};
However, this produces
<Amt Ccy="EUR"><_content>158.4</_content><Amt>
I know the example #4 had only one tag, so I mixed it with example #7 and added a string instead of an object to the _content object.
I tried to do it with two steps(first add attribute, then add content), but couldn't figure out that either
Tried it with name attrtibute as well:
this.creditTransferTxXml.CdtTrfTxInf.Amt = {_name: 'Amt', _attrs: {Ccy:SEPAInfo.payment.currency}, _content: SEPAInfo.payment.amount.toString()};
However, this produced what I want, and then an extra tag wrapped around it
<Amt><Amt Ccy="EUR">158.4</Amt></Amt>
Syntactically it tries to add and Amt element to existing Amt element. I'm just trying to modfy the existing one
The text was updated successfully, but these errors were encountered: