我使用perl腳本生成新的XML文件,但我小問題,我寫這樣的腳本如何用perl
#!/usr/bin/perl
use warnings;
use strict;
open my $file, '>>', 'data.xml' or die "Can't open file: $!";
print $file (<<EOF);
<?xml version="1.0" encoding="UTF-8"?>
<Detailsofuniversitys xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Identification>
<Ind>03.20.00</Ind>
</Identification>
<MetaData>
<History>
<Entry>
<Date>2010-10-19</Date>
<Note>IND Created</Note>
</Entry>
</History>
<Status>P</Status>
<StoringAndErasing>Not Defined</StoringAndErasing>
<StoringAndErasing>Not Defined</StoringAndErasing>
</MetaData>
<university>
<name>svu</name>
<location>ravru</location>
<branch>
<electronics>
<student name="xxx" number="12">
<semester number="1"subjects="7" rank="2"/>
</student>
<student name="xxx" number="15">
<semester number="1" subjects="7" rank="10"/>
<semester number="2" subjects="4" rank="1"/>
</student>
<student name="xxx" number="16">
<semester number="1"subjects="7" rank="2"/>
<semester number="2"subjects="4" rank="2"/>
</student>
</electronics>
</branch>
</university>
<university>
<name>sku</name>
<location>ANTP</location>
<branch>
<electronics>
<student name="xxx" number="12">
<semester number="3"subjects="6" rank="20"/>
</student>
<student name="xxx" number="16">
<semester number="1"subjects="9" rank="12"/>
<semester number="2"subjects="4" rank="2"/>
</student>
</section>
</electronics>
</branch>
</university>
EOF
但運行此腳本後,它不給任何錯誤genarate新的XML文件,它genarating xml文件,當我試圖打開XML文件
The XML page cannot be displayed
Cannot view XML input using XSL style sheet. Please correct the error and then click
the Refresh button, or try again later.
The following tags were not closed: gpx, gpx, detailsofuniversitys. Error processing
resource 'file:///C:/files/star/data...
我不知道什麼是錯誤是這樣,怎麼開。在perl腳本中是否有任何錯誤。如何使用perl生成新的xml文件(xml數據如下所示),是否有任何選項。
將其縮小爲微小的xml輸出,然後重試。你用什麼來打開文件? – KevinDTimm
可能的重複[如何從Perl創建XML?](http://stackoverflow.com/questions/154762/how-can-i-create-xml-from-perl) – daxim
您正在寫入的字符串文件不是有效的XML。標籤已打開,但未關閉。這個問題與Perl無關。問題出在您的文檔上。 –