【发布时间】:2022-01-20 23:42:26
【问题描述】:
在我的专有应用程序中,我有一个具有以下结构的 XML 字段
<?xml version='1.0'?>
<recipient>
<comment></comment>
<changes firstName=""/>
</recipient>
我可以使用以下脚本写入它。
var recipient = NLWS.nmsRecipient.create(
{recipient:{
email : 'dummy@dummy.com',
lastName : 'D',
firstName : 'G',
origin : 'Preference Centre'}})
recipient.changes.firstName = 'tmpName'
recipient.comment = "CommentsHere";
recipient.save();
虽然上述方法有效,但我想知道为什么我不能使用以下方式。
var recipient = NLWS.nmsRecipient.create(
{recipient:{
email : 'dummy@dummy.com',
lastName : 'D',
firstName : 'G',
origin : 'Preference Centre'
changes.firstName : 'tmpFirstName'}})
recipient.comment = "CommentsHere";
recipient.save();
我尝试了以下变体都无济于事,正确的方法是什么?
[changes/@firstName] : 'tmpFirstName'
[changes.firstName] : 'tmpFirstName'
{changes.firstName} : 'tmpFirstName'
{"changes":"firstName"} : 'tmpFirstName'
更新
为了能够扩展我的架构/表,我对我的架构进行了以下更改
<!--tmp recipient changes 18122021 DG-->
<element label="changes" name="changes" xml="true">
<attribute label="tmp firstName" name="firstName" type="string" xml="true"/>
<attribute label="tmp LastName" name="lastName" type="string" xml="true"/>
<attribute label="tmp email" name="email" type="string" xml="true"/>
<attribute label="tmp emailPreferredName" name="emailPreferredName" type="string"
xml="true"/>
<attribute label="tmp JOB_TITLE" name="JOB_TITLE" type="string" xml="true"/>
<attribute label="tmp company" name="company" type="string" xml="true"/>
<attribute label="tmp blackListEmail" name="blackListEmail" type="string"
xml="true"/>
<attribute label="tmp lawfulBasis" name="lawfulBasis" type="string" xml="true"/>
</element>
<!--tmp recipient changes -->
因此我可以使用 XML xpath 将数据存储在单个 mData 字段(数据)中
var recipient = NLWS.nmsRecipient.create(
{recipient:{
email : 'dummy@dummy.com',
lastName : 'D',
firstName : 'G',
origin : 'Preference Centre'}})
recipient.changes.firstName = 'tmpName'
recipient.changes.lastName= 'tmpName'
recipient.changes.company= 'tmpCompany'
recipient.comment = "CommentsHere";
recipient.save();
【问题讨论】:
-
changes.firstName 可能在构造函数中不存在,但在创建函数中的其他位置添加
-
你可以在这里问github.com/adobe/acc-js-sdk
标签: javascript json xml