gpt4 book ai didi

javascript - 如何使用 javascript/jquery 操作 xml 文件

转载 作者:行者123 更新时间:2023-11-28 00:56:53 24 4
gpt4 key购买 nike

我需要操作页面上的 xml 文件。 XML 包含 1 到 n 个类型字段元素。每个字段包含一个数据库名称。有了这些信息,我需要创建一个新的显示标签,并且需要在其中添加每个 1 到 n 字段元素

这是我的源 xml

    <form>
<version>DE_TEST_1</version>
<description>METAXA V3.7.5-0 generated Meta Data XML for Form</description>
<author>METAXA</author>
<date>2014-09-02T15:59:31.428+02:00</date>
<pages height="297.0000885009766" width="210.00014478895395">
<page fillWithPattern="true" order="1">
<clips>
<clip display="SHOW" height="148.5" id="obere Hälfte" width="210.0" xPos="0.0" yPos="0.0"/>
<clip display="SHOW" height="148.5" id="untere Hälfte" width="210.0" xPos="0.0" yPos="148.5"/>
<clip display="SHOW" height="297.0" id="komplett" width="210.0" xPos="0.0" yPos="0.0"/>
</clips>
</page>
</pages>
</form>
<fields>
<field dbName="txt_StartRZ1_6" exportname="txt_StartRZ1_6" id="txt_StartRZ1_6" order="344" originX="0.0" originY="0.0" page="1" type="text" withprefill="false">
<fixedvalue/>
<storage type="string"/>
<hwr country="DE" dataformat="DIGIT" language="de" strokemapping="center_of_gravitiy"/>
<layout ismultiarea="true">
<font alignment="LEFT" color="#000000" name="Arial" size="10.0" style="NORMAL"/>
<area height="6.462202453613281" id="0" width="4.8778568691677515" xPos="42.004897308349605" yPos="109.39709082709422"/>
<area height="0.8382132636176215" id="2" width="0.5831416236029731" xPos="41.31027723948161" yPos="109.43731231689455"/>
<area height="6.462202453613281" id="1" width="4.8778568691677515" xPos="47.003407880995006" yPos="109.39709082709422"/>
<area height="6.4621809217664925" id="4" width="4.8778568691677515" xPos="56.999718475341794" yPos="109.35689086914064"/>
<area height="6.462202453613281" id="3" width="4.8778568691677515" xPos="52.0015631781684" yPos="109.39709082709422"/>
</layout>
</field>
</fields>

应像底部的示例一样生成新的附加显示标记。

<display>
<labels>
<fieldlabels>
<label labelid="txt_StartRZ1_6">
<text>txt_StartRZ1_6</text>
<text locale="en">txt_StartRZ1_6</text>
</label>
</fieldlabels>
<grouplabels>
</grouplabels>
<rangelabels>
</rangelabels>
<strings/>
</labels>
<styles>
<style selector="txt_StartRZ1_5"/>
<style selector="txt_StartRZ1_6"/>
</styles>
<channels>
<channel name="tablet">
<viewdef name="landscape">
<section descriptionId="section__id_description" id="section__id" labelStyle="section__id_label_style" shortTitleId="section__id_short_title" style="section__id_style" titleId="section__id_title">
<panel descriptionId="panel__id_description" id="panel__id" style="panel__id_style" titleId="panel__id_title">
<item id="txt_StartRZ1_6_item_id" ref="txt_StartRZ1_6">
<widget id="txt_StartRZ1_6_widget_id" widget="TEXTFIELD"/>
</item>
</panel>
</section>
</viewdef>
</channel>
</channels>
</display>

是否有 javascript/jquery 库可供我使用?

感谢您的建议

最佳答案

答案是......是的!

查看这个现有问题,它本质上是对您的问题的重述,但输入较小:How to parse xml using jquery

从那里的答案:

jQuery.parseXML:http://api.jquery.com/jQuery.parseXML/

示例:

var xml = $.parseXML(yourfile.xml),
$xml = $( xml ),
$test = $xml.find('test');

console.log($test.text());

关于javascript - 如何使用 javascript/jquery 操作 xml 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26123388/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com