简体   繁体   English

如何使用Javascript查找内部文本 <g:id> 文本 </g:id> 并先粘贴 <g:mpn> 多布卢 </g:mpn> 标签

[英]How can I use Javascript to find text inside <g:id>Text</g:id> and paste on first <g:mpn>DOLBLUU</g:mpn> tag

How can I use Javascript to find text inside <g:id>Text</g:id> and paste on first <g:mpn>DOLBLUU</g:mpn> tag 如何使用Javascript在<g:id>Text</g:id>查找文本并将其粘贴在第一个<g:mpn>DOLBLUU</g:mpn>标记上

Example: I want to loop through the XML document and find the <g:id> and get text and paste on the first <g:mpn> tag that it finds. 示例:我想遍历XML文档并找到<g:id>并获取文本并粘贴到它找到的第一个<g:mpn>标记上。

<item><g:id>DOLBLUU</g:id><g:mpn>DOLBLUU</g:mpn>

Does anyone know how to accomplish this? 有谁知道如何做到这一点?

If you are proposing to grab XML from a text area and parse it, then you should take a look at these Javascript XML-related libs. 如果您打算从文本区域中获取XML并进行解析,那么您应该看看这些与Javascript XML相关的库。 In particular, you might want to check out XPATH, which allows you to reference any part of an XML document, according to a nutty-but-powerful query syntax. 特别是,您可能想检出XPATH,该XPATH使您可以根据功能丰富但功能强大的查询语法来引用XML文档的任何部分。 If I understand what you're asking for, XPATH is probably it, but you'll see a few related items under "XML Technology" on the XML Parser Javascript docs page . 如果我了解您的要求,则可能是XPATH,但是您会在XML Parser Javascript docs页面上的“ XML Technology”下看到一些相关项目。

If I'm off the mark, perhaps you can provide samples of input and expected output with a little more explanation. 如果我不负责任的话,也许您可​​以提供输入样本和预期输出,并提供更多解释。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM