如何使用 javascript 将新属性动态插入到 xml 标记中?
我有一些如下所示的 xml:
<dict>
<key>Track ID</key>
<integer>4896</integer>
<key>Name</key>
<string>Let 'cha Boy Go (DIRTY) F/B.o.B</string>
<key>Artist</key>
<string>4-Ize</string>
<key>Grouping</key>
<string>www.2dopeboyz.com</string>
<key>Genre</key>
<string>Hip-Hop</string>
<key>Kind</key>
<string>MPEG audio file</string>
<key>Size</key>
<integer>5837048</integer>
<key>Total Time</key>
<integer>243121</integer>
<key>Year</key>
<integer>2010</integer>
<key>BPM</key>
<integer>80</integer>
<key>Date Modified</key>
<date>2010-09-05T05:51:23Z</date>
<key>Date Added</key>
<date>2010-09-04T15:37:43Z</date>
<key>Bit Rate</key>
<integer>192</integer>
<key>Sample Rate</key>
<integer>44100</integer>
<key>Comments</key>
<string>80.3</string>
<key>Normalization</key>
<integer>7646</integer>
<key>Persistent ID</key>
<string>D9FAAD3E0203FA18</string>
<key>Track Type</key>
<string>File</string>
<key>Location</key>
</dict>
How do I write the JavaScript to insert attribute on certain labels?
I have some xml like the following:
<dict>
<key>Track ID</key>
<integer>4896</integer>
<key>Name</key>
<string>Let 'cha Boy Go (DIRTY) F/B.o.B</string>
<key>Artist</key>
<string>4-Ize</string>
<key>Grouping</key>
<string>www.2dopeboyz.com</string>
<key>Genre</key>
<string>Hip-Hop</string>
<key>Kind</key>
<string>MPEG audio file</string>
<key>Size</key>
<integer>5837048</integer>
<key>Total Time</key>
<integer>243121</integer>
<key>Year</key>
<integer>2010</integer>
<key>BPM</key>
<integer>80</integer>
<key>Date Modified</key>
<date>2010-09-05T05:51:23Z</date>
<key>Date Added</key>
<date>2010-09-04T15:37:43Z</date>
<key>Bit Rate</key>
<integer>192</integer>
<key>Sample Rate</key>
<integer>44100</integer>
<key>Comments</key>
<string>80.3</string>
<key>Normalization</key>
<integer>7646</integer>
<key>Persistent ID</key>
<string>D9FAAD3E0203FA18</string>
<key>Track Type</key>
<string>File</string>
<key>Location</key>
</dict>
How do I write the JavaScript to insert attributes on certain tags?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
XmlDOM
加载 xml,使用 XPath 查找元素,然后进行 DOM 操作来修改它:You can load the xml using
XmlDOM
, use XPath to find an element and then DOM manipulation to modify it: