如何使用XML :: Writer perl插入XML(How to insert XML using XML::Writer perl)
我试图建立一个可以根据输入的内容动态创建xml的系统。 我有一个总是相同的seleton,并且唯一需要动态创建的是formfields。 因此,例如,我需要将$ testXML插入到我的$ writer XML中。 这是我到目前为止所拥有的
use strict; use warnings; use XML::Writer; my $test = XML::Writer->new(OUTPUT => 'self', DATA_MODE => 1, DATA_INDENT => 2, ); $test->startTag('FormField', name => 'CheckBox1'); $test->startTag('Value'); $test->characters(''); $test->endTag('Value'); $test->endTag('FormField'); my $testXML = $test->end();
插入
my $writer = XML::Writer->new(OUTPUT => 'self', DATA_MODE => 1, DATA_INDENT => 2, ); $writer->startTag('Section', name => 'FormSectionOne'); $writer->startTag('FormField', name => 'Person1'); $writer->startTag('Value'); $writer->characters('Bob Test'); $writer->endTag('Value'); $writer->endTag('FormField'); $testXML; my $xml = $writer->end(); print $xml;
现在使用$ writer-> raw($ testXML); 插入,但格式有问题
<Section name="FormSectionOne"> <FormField name="Person1"> <Value>Bob Test</Value> </FormField><FormField name="CheckBox1"> <Value>test</Value>
Im trying to make a system that can dynamically create xml based on what is entered. I have a seleton that will always be the same, and the only thing that need to be created dynamically is the formfields. So for example, I need to insert $testXML into my $writer XML. Here is what I have so far
use strict; use warnings; use XML::Writer; my $test = XML::Writer->new(OUTPUT => 'self', DATA_MODE => 1, DATA_INDENT => 2, ); $test->startTag('FormField', name => 'CheckBox1'); $test->startTag('Value'); $test->characters(''); $test->endTag('Value'); $test->endTag('FormField'); my $testXML = $test->end();
Inserted into
my $writer = XML::Writer->new(OUTPUT => 'self', DATA_MODE => 1, DATA_INDENT => 2, ); $writer->startTag('Section', name => 'FormSectionOne'); $writer->startTag('FormField', name => 'Person1'); $writer->startTag('Value'); $writer->characters('Bob Test'); $writer->endTag('Value'); $writer->endTag('FormField'); $testXML; my $xml = $writer->end(); print $xml;
Now using $writer->raw($testXML); inserts but the formatting has problems
<Section name="FormSectionOne"> <FormField name="Person1"> <Value>Bob Test</Value> </FormField><FormField name="CheckBox1"> <Value>test</Value>
原文:https://stackoverflow.com/questions/39820452
最满意答案
您可以找到
value="0"
的元素的数量,并将其与总计数进行比较以hide()
与类points__fees
最接近的元素:var count = $('.points__fees__input[value="0"]').filter(function(){ return this.value === "0"; }).get(); if($('.points__fees__input[value]').length == count.length) $('.points__fees__input[value="0"]').closest('.points__fees').hide();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="points__fees"> <div class="points__fees__label">Fees / Charges</div> <div class="points__fees__value"> <div class="points__fees__value__item" data-type="star$"> <span class="points__fees__text">0</span> Star $ <input class="points__fees__input" value="0" type="hidden"> </div> <div class="points__fees__value__item" data-type="diamond$"> <span class="points__fees__text">0</span> Diamond $ <input class="points__fees__input" value="0" type="hidden"> </div> <div class="points__fees__value__item" data-type="gold$"> <span class="points__fees__text">0</span> Gold $ <input class="points__fees__input" value="0" type="hidden"> </div> </div> </div>
You can find the count of elements with
value="0"
and compare that with total count tohide()
the closest element with classpoints__fees
:var count = $('.points__fees__input[value="0"]').filter(function(){ return this.value === "0"; }).get(); if($('.points__fees__input[value]').length == count.length) $('.points__fees__input[value="0"]').closest('.points__fees').hide();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="points__fees"> <div class="points__fees__label">Fees / Charges</div> <div class="points__fees__value"> <div class="points__fees__value__item" data-type="star$"> <span class="points__fees__text">0</span> Star $ <input class="points__fees__input" value="0" type="hidden"> </div> <div class="points__fees__value__item" data-type="diamond$"> <span class="points__fees__text">0</span> Diamond $ <input class="points__fees__input" value="0" type="hidden"> </div> <div class="points__fees__value__item" data-type="gold$"> <span class="points__fees__text">0</span> Gold $ <input class="points__fees__input" value="0" type="hidden"> </div> </div> </div>
相关问答
更多-
如何在焦点上隐藏div的子元素(在java脚本中)(how to hide a div on focus-out of child elements of that div(in java script))[2024-01-12]
通常,您询问如何检测元素外部的单击。 这个问题在这里得到了很好的回答。 另外,这里有一个小提示,显示如何处理隐藏和重新显示您的用例。 我真正添加的唯一一件事就是显示用于重新显示用户名/密码div的任何按钮/方法都需要使用相同类型的event.stopPropagation()来避免重新隐藏您要显示的内容。 HTML: