我一直试图找到节点并打印文本内容,但是我尝试打印没有任何反应
这是我的xml
<leg:level>
<leg:level-vrnt leveltype="chapter">
<leg:levelbody>
<leg:bodytext>
<leg:heading align="center">
<desig inline="false" searchtype="CHAPTER-NUM">
<desiglabel>CHAPTER</desiglabel>
<designum>II</designum>
</desig>
<title searchtype="CHAPTER-TITLE">[EMPLOYEE’S] COMPENSATION</title>
</leg:heading>
</leg:bodytext>
<leg:level>
<leg:level-vrnt leveltype="prov1" searchtype="SECTION">
<leg:levelbody>
<leg:bodytext searchtype="SECTION">
<leg:heading align="left" searchtype="SECTION">
<desig inline="true" searchtype="PROVISION-SECTION">
<desiglabel>SECTION</desiglabel>
<designum>4</designum>
</desig>
<title searchtype="SECTION-TITLE">
<refpt type="ext" id="EMPCOM_ACT_00004">Amount of compensation.</refpt>
</title>
</leg:heading>
</leg:bodytext>
<leg:level>
<leg:level-vrnt leveltype="prov2" searchtype="LEGISLATION">
<leg:levelbody>
<leg:bodytext searchtype="LEGISLATION">
<l>
<li>
<lilabel><fnr fntoken="FN_000001" fnrtoken="FNR_000001"
>1</fnr></lilabel>
<p>
<text>
follows, namely:—</text>
</p>
<l>
<li>
<lilabel>(<emph typestyle="it">a</emph>)</lilabel>
<p>
<text>Where death results from the injury</text>
<text align="right">an amount equal to <fnr fntoken="FN_000002"
fnrtoken="FNR_000002">2</fnr>[fifty per cent.] of the monthly
wage of the deceased <fnr fntoken="FN_000003" fnrtoken="FNR_000003"
>3</fnr>[employee] multiple by the relevant factor;</text>
</p>
<p>
<text align="center">or</text>
</p>
<p>
<text align="right">an amount of <fnr fntoken="FN_000004" fnrtoken="FNR_000004"
>4</fnr>[one lakh and twenty thouand rupees], whichever is
more;</text>
</p>
</li>
<li>
<lilabel>(<emph typestyle="it">b</emph>)</lilabel>
<p>
<text>Where permanent total disablement results from the injury</text>
<text align="right">an amount equal to <fnr fntoken="FN_000002"
fnrtoken="FNR_000002">2</fnr>[sixty per cent.] of the monthly
wages of the injured <fnr fntoken="FN_000003" fnrtoken="FNR_000003"
>3</fnr>[employee] multiplied by the relevant factor,</text>
</p>
<p>
<text align="center">or</text>
</p>
<p>
<text align="right">an amount of <fnr fntoken="FN_000005" fnrtoken="FNR_000005"
>5</fnr>[one lakh and forty thousand rupees], whichever is
more:</text>
</p>
<p>
<text><fnr fntoken="FN_000006" fnrtoken="FNR_000006">6</fnr>[Provided that
the Central Government may, by notification in the Official Gazette, from time
to time, enhance the amount of compensation mentioned in clauses (<emph
typestyle="it">a</emph>) and (<emph typestyle="it"
>b</emph>).]</text>
</p>
<p>
<text><emph typestyle="it">Explanation I</emph>.—For the purposes of clause
(<emph typestyle="it">a</emph>) and clause (<emph
typestyle="it">b</emph>), <deflist><defitem id="EMPCOM_ACT_000001"
><defterm><refpt type="ext" id="EMPCOM_ACT_000001"/>“relevant
factor”,</defterm>
<defdesc><p><text>in relation to a <fnr fntoken="FN_000003"
fnrtoken="FNR_000003">3</fnr>[employee] means the factor
specified in the second column of Schedule IV against the entry in the
first column of that Schedule specifying the number of years which are the
same as the completed years of the age of the <fnr fntoken="FN_000003"
fnrtoken="FNR_000003">3</fnr>[employee] on his last birthday
immediately preceding the date on which the compensation fell
due.</text></p></defdesc></defitem></deflist></text>
</p>
<p>
<text><fnr fntoken="FN_000007" fnrtoken="FNR_000007">7</fnr>[*
* *]</text>
</p>
</li>
<li>
<lilabel>(<emph typestyle="it">c</emph>)</lilabel>
<p>
<text>Where permanent partial disablement results from the injury</text>
<text align="right">(<emph typestyle="it">i</emph>) in the case of
an injury specified in Part
injury, and</text>
</p>
</li>
<li>
<lilabel>(<emph typestyle="it">ii</emph>)</lilabel>
<p>
<text align="right">in the case of an injury not specified in Schedule I, such
percentage of the compensation payable in the case of permanent total
disablement as is proportionate to the loss of earning capacity (as
assessed by the qualified medical practitioner) permanently caused by
the injury.</text>
</p>
<p>
<text><emph typestyle="it">Explanation I</emph>.—Where more injuries than
one are caused by the same accident, the amount of compensation payable under
this head shall be aggregated but not so in any case as to exceed the amount
which would have been payable if permanent total disablement had resulted from
the injuries.</text>
</p>
<p>
<text><emph typestyle="it">Explanation II</emph>.—In assessing the loss of
earning capacity for the purposes of sub-clause (<emph typestyle="it"
>ii</emph>), the qualified medical practitioner shall have due
regard to the percentages of loss of earning capacity in relation to different
injuries specified in Schedule I;</text>
</p>
</li>
<li>
<lilabel>(<emph typestyle="it">d</emph>)</lilabel>
<p>
<text>Where temporary disablement, whether total or partial, results from the
injury</text>
<text align="right">a half-monthly payment of the um equivalent to twenty-five per
cent. of monthly wages of the <fnr fntoken="FN_000008" fnrtoken="FNR_000008"
>8</fnr>[employee], to be paid in accordance with the
provisions of sub-section (2).</text>
</p>
</li>
</l>
</li>
<li>
<lilabel><fnr fntoken="FN_000009" fnrtoken="FNR_000009"
>9</fnr>[(1-A)</lilabel>
<p>
<text>Notwithstanding anything contained in sub-section (1), while fixing
the amount of compensation payable to a <fnr fntoken="FN_000008" fnrtoken="FNR_000008"
>8</fnr>[employee] in respect of an accident occurred outside India,
the Commissioner shall take into account the amount of compensation, if any, awarded
to such <fnr fntoken="FN_000008" fnrtoken="FNR_000008">8</fnr>[employee]
in accordance with the law of the country in which the accident occurred and shall
reduce the amount fixed by him by the amount of compensation awarded to the <fnr
fntoken="FN_000008" fnrtoken="FNR_000008">8</fnr>[employee] in
accordance with the law of that country.]</text>
</p>
</li>
<li>
<lilabel><fnr fntoken="FN_000010" fnrtoken="FNR_000010"
>10</fnr>[(1-B)</lilabel>
<p>
<text>The Central Government may, by notification in the Official Gazette, specify, for
the purposes of sub-section (1), such monthly wages in relation to an
employee as it may consider necessary.]</text>
</p>
</li>
<li>
<lilabel>(2)</lilabel>
<p>
<text>The half-monthly payment referred to in clause (<emph typestyle="it"
>d</emph>) of sub-section (1) shall be payable on the sixteenth
day—</text>
</p>
<l>
<li>
<lilabel>(<emph typestyle="it">i</emph>)</lilabel>
<p>
<text>from the date of disablement where such disablement lasts for a period of
twenty-eight days or more, or</text>
</p>
</li>
<li>
<lilabel>(<emph typestyle="it">ii</emph>)</lilabel>
<p>
<text>after the expiry of a waiting period of three days from the date of
disablement where such disablement lasts for a period of less than
twenty-eight days; and thereafter half-monthly during the disablement or
during a period of five years, whichever period is shorter:</text>
</p>
<p>
<text>Provided that—</text>
</p>
<l>
<li>
<lilabel>(<emph typestyle="it">a</emph>)</lilabel>
<p>
<text>there shall be deducted from any lump sum or half-monthly payments to
which the <fnr fntoken="FN_000011" fnrtoken="FNR_000011"
>11</fnr>[employee] is entitled the amount of any payment or
allowance which the <fnr fntoken="FN_000011" fnrtoken="FNR_000011"
>11</fnr>[employee] has received from the employer by way of
compensation during the period of disablement prior to the receipt of such
lump sum or of the first half-monthly payment, as the case may be;
and</text>
</p>
</li>
<li>
<lilabel>(<emph typestyle="it">b</emph>)</lilabel>
<p>
<text>no half-monthly payment shall in any case exceed the amount, if any,
by which half the amount of the monthly wages of the <fnr
fntoken="FN_000011" fnrtoken="FNR_000011">11</fnr>[employee]
before the accident exceeds half the amount of such wages which he is
earning after the accident.</text>
</p>
<p>
<text><emph typestyle="it">Explanation</emph>.—Any payment or
allowance which the <fnr fntoken="FN_000011" fnrtoken="FNR_000011"
>11</fnr>[employee] has received from the employer towards
his medical treatment shall not be deemed to be a payment or allowance
received by him by way of compensation within the meaning of clause
(<emph typestyle="it">a</emph>) of the proviso.</text>
</p>
</li>
</l>
</li>
<li>
<lilabel><fnr fntoken="FN_000012" fnrtoken="FNR_000012"
>12</fnr>[(2-A)</lilabel>
<p>
<text>The employee shall be reimbursed the actual medical expenditure incurred by
him for treatment of injuries caused during the course of
employment.]</text>
</p>
</li>
<li>
<lilabel>(3)</lilabel>
<p>
<text>
half-month.]</text>
</p>
</li>
<li>
<lilabel><fnr fntoken="FN_000013" fnrtoken="FNR_000013"
>13</fnr>[(4)</lilabel>
<p>
<text>If the injury of the <fnr fntoken="FN_000011" fnrtoken="FNR_000011"
>11</fnr>[employee] results <fnr fntoken="FN_000014" fnrtoken="FNR_000014"
>14</fnr>[not less than five thousand
the same to the eldest surviving dependant of the <fnr fntoken="FN_000011"
fnrtoken="FNR_000011">11</fnr>[employee] towards the
expenditure of the funeral of such <fnr fntoken="FN_000011"
fnrtoken="FNR_000011">11</fnr>[employee] or where the <fnr
fntoken="FN_000011" fnrtoken="FNR_000011">11</fnr>[employee]
did not have a dependant or was not living with his dependant at the time of
his death to the person who actually incurred such expenditure:]</text>
</p>
<p>
<text><fnr fntoken="FN_000015" fnrtoken="FNR_000015">15</fnr>[Provided that
the Central Government may, by notification in the Official Gazette, from time
to time, enhance the amount specified in this sub-section.]</text>
</p>
</li>
</l>
</li>
</l>
<pgrp>
<heading searchtype="commentary">
<title align="center">
<emph typestyle="bf">COMMENTS</emph>
</title>
</heading>
<blockquote>
这是我的代码
use strict;
use warnings;
use XML::LibXML;
my $filename = "data1.xml";
my $parser = XML::LibXML->new();
my $xmldoc = $parser->parse_file($filename);
my $t = $xmldoc->getDocumentElement;
for my $sample ( $t->findnodes("/l/li/lilabel") ) {
print $sample->textContent(),"\n";
}
在此代码中查找文字:<lilabel>knldk</lilabel>
答案 0 :(得分:1)
您需要调整xpath。
基本上,您希望在任何ancester中查找这些元素,而不仅仅是根节点的子节点,因此请使用:
for my $sample ( $t->findnodes("//l/li/lilabel") ) {
的基本知识