0
XML을 사용하여 Perl을 사용하고 있습니다. Simple을 사용하여 해시를 XML 문서로 변환합니다.XML :: Simple, XML 노드가 'name'노드의 값으로 변경되었습니다.
이#!/usr/bin/perl
use strict;
use warnings;
use XML::Simple;
use Data::Dumper;
my $xml_simple = XML::Simple->new(NoAttr => 1,
KeepRoot => 1);
my $hash = { output => { 'products' => [ { 'product' => { 'titel' => 'ABN AMRO Bank hypotheken',
'owner' => 'ABN AMRO Hypotheken Groep',
'code' => 'ABN AMRO BANK R' } },
{ 'product' => { 'titel' => 'Aegon',
'owner' => 'AEGON Hypotheken',
'code' => 'AEGON pilot' } } ],
'date' => '2012-02-20'} };
my $xml = $xml_simple->XMLout($hash);
print Dumper($xml);
내가 무엇입니까 출력은 다음과 같습니다 :
<output>
<date>2012-02-20</date>
<products>
<name>product</name>
<code>ABN AMRO BANK R</code>
<owner>ABN AMRO Hypotheken Groep</owner>
<titel>ABN AMRO Bank hypotheken</titel>
</products>
<products>
<name>product</name>
<code>AEGON pilot</code>
<owner>AEGON Hypotheken</owner>
<titel>Aegon</titel>
</products>
</output>
하지만 내가 찾고 있어요 것은이합니다 ('제품'노드 참조) 다음과 같이
내 스크립트 보인다
<output>
<date>2012-02-20</date>
<products>
<product>
<code>ABN AMRO BANK R</code>
<owner>ABN AMRO Hypotheken Groep</owner>
<titel>ABN AMRO Bank hypotheken</titel>
</product>
<product>
<code>AEGON pilot</code>
<owner>AEGON Hypotheken</owner>
<titel>Aegon</titel>
</product>
</products>
</output>
XML로이 행할 수 있습니까 :: 단순하거나 다른 모듈을 사용해야합니까?
일을 원하는 것을 말할하도록 할 수 있습니다. 명시 적으로 코드에서 한 가지만 설명하려면 XMLout에 ForceArray를 설정하지 않아도됩니다. – daxim
감사합니다. Philip. 실제로 해시 구조로 놀아서 대답하기 바로 전에 실제로 작동하게했습니다. 자신의 방식대로 (예 : XML로 간단하게 필요한 것을 알려줌으로써) 고통을 덜 덜 수 있습니다. –
'KeyAttr => {}'매개 변수를 사용하여 배열 접기를 사용 불가능하게하면 XML의 재구성이 중지됩니다. – Borodin