打印节点内容没有任何反应

时间:2014-04-10 07:40:10

标签: xml perl perl-module perl-data-structures

我一直试图找到节点并打印文本内容,但是我尝试打印没有任何反应

这是我的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">&#x005B;EMPLOYEE&#x2019;S&#x005D; 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:&#x2014;</text>
                                                    </p>
                                                    <l>
                                                        <li>
                                                            <lilabel>&#x0028;<emph typestyle="it">a</emph>&#x0029;</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>&#x005B;fifty per cent.&#x005D; of the monthly
                                                                    wage of the deceased <fnr fntoken="FN_000003" fnrtoken="FNR_000003"
                                                                    >3</fnr>&#x005B;employee&#x005D; 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>&#x005B;one lakh and twenty thouand rupees&#x005D;, whichever is
                                                                    more;</text>
                                                            </p>
                                                        </li>
                                                        <li>
                                                            <lilabel>&#x0028;<emph typestyle="it">b</emph>&#x0029;</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>&#x005B;sixty per cent.&#x005D; of the monthly
                                                                    wages of the injured <fnr fntoken="FN_000003" fnrtoken="FNR_000003"
                                                                    >3</fnr>&#x005B;employee&#x005D; 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>&#x005B;one lakh and forty thousand rupees&#x005D;, whichever is
                                                                    more:</text>
                                                            </p>
                                                            <p>
                                                                <text><fnr fntoken="FN_000006" fnrtoken="FNR_000006">6</fnr>&#x005B;Provided that
                                                                    the Central Government may, by notification in the Official Gazette, from time
                                                                    to time, enhance the amount of compensation mentioned in clauses &#x0028;<emph
                                                                       typestyle="it">a</emph>&#x0029; and &#x0028;<emph typestyle="it"
                                                                    >b</emph>&#x0029;.&#x005D;</text>
                                                            </p>
                                                            <p>
                                                                <text><emph typestyle="it">Explanation I</emph>.&#x2014;For the purposes of clause
                                                                       &#x0028;<emph typestyle="it">a</emph>&#x0029; and clause &#x0028;<emph
                                                                       typestyle="it">b</emph>&#x0029;, <deflist><defitem id="EMPCOM_ACT_000001"
                                                                       ><defterm><refpt type="ext" id="EMPCOM_ACT_000001"/>&#x201C;relevant
                                                                       factor&#x201D;,</defterm>
                                                                       <defdesc><p><text>in relation to a <fnr fntoken="FN_000003"
                                                                       fnrtoken="FNR_000003">3</fnr>&#x005B;employee&#x005D; 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>&#x005B;employee&#x005D; 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>&#x005B;&#x002A;
                                                                    &#x002A; &#x002A;&#x005D;</text>
                                                            </p>
                                                        </li>
                                                        <li>
                                                            <lilabel>&#x0028;<emph typestyle="it">c</emph>&#x0029;</lilabel>
                                                            <p>
                                                                <text>Where permanent partial disablement results from the injury</text>
                                                                <text align="right">&#x0028;<emph typestyle="it">i</emph>&#x0029; in the case of
                                                                    an injury specified in Part 


                                              injury, and</text>
                                                            </p>
                                                        </li>
                                                        <li>
                                                            <lilabel>&#x0028;<emph typestyle="it">ii</emph>&#x0029;</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 &#x0028;as
                                                                    assessed by the qualified medical practitioner&#x0029; permanently caused by
                                                                    the injury.</text>
                                                            </p>
                                                            <p>
                                                                <text><emph typestyle="it">Explanation I</emph>.&#x2014;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>.&#x2014;In assessing the loss of
                                                                    earning capacity for the purposes of sub-clause &#x0028;<emph typestyle="it"
                                                                       >ii</emph>&#x0029;, 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>&#x0028;<emph typestyle="it">d</emph>&#x0029;</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>&#x005B;employee&#x005D;, to be paid in accordance with the
                                                                    provisions of sub-section &#x0028;2&#x0029;.</text>
                                                            </p>
                                                        </li>
                                                    </l>
                                                </li>
                                                <li>
                                                    <lilabel><fnr fntoken="FN_000009" fnrtoken="FNR_000009"
                                                        >9</fnr>&#x005B;&#x0028;1-A&#x0029;</lilabel>
                                                    <p>
                                                        <text>Notwithstanding anything contained in sub-section &#x0028;1&#x0029;, while fixing
                                                            the amount of compensation payable to a <fnr fntoken="FN_000008" fnrtoken="FNR_000008"
                                                                >8</fnr>&#x005B;employee&#x005D; 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>&#x005B;employee&#x005D;
                                                            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>&#x005B;employee&#x005D; in
                                                            accordance with the law of that country.&#x005D;</text>
                                                    </p>
                                                </li>
                                                <li>
                                                    <lilabel><fnr fntoken="FN_000010" fnrtoken="FNR_000010"
                                                        >10</fnr>&#x005B;&#x0028;1-B&#x0029;</lilabel>
                                                    <p>
                                                        <text>The Central Government may, by notification in the Official Gazette, specify, for
                                                            the purposes of sub-section &#x0028;1&#x0029;, such monthly wages in relation to an
                                                            employee as it may consider necessary.&#x005D;</text>
                                                    </p>
                                                </li>
                                                <li>
                                                    <lilabel>&#x0028;2&#x0029;</lilabel>
                                                    <p>
                                                        <text>The half-monthly payment referred to in clause &#x0028;<emph typestyle="it"
                                                            >d</emph>&#x0029; of sub-section &#x0028;1&#x0029; shall be payable on the sixteenth
                                                            day&#x2014;</text>
                                                    </p>
                                                    <l>
                                                        <li>
                                                            <lilabel>&#x0028;<emph typestyle="it">i</emph>&#x0029;</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>&#x0028;<emph typestyle="it">ii</emph>&#x0029;</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&#x2014;</text>
                                                            </p>
                                                            <l>
                                                                <li>
                                                                    <lilabel>&#x0028;<emph typestyle="it">a</emph>&#x0029;</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>&#x005B;employee&#x005D; is entitled the amount of any payment or
                                                                       allowance which the <fnr fntoken="FN_000011" fnrtoken="FNR_000011"
                                                                       >11</fnr>&#x005B;employee&#x005D; 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>&#x0028;<emph typestyle="it">b</emph>&#x0029;</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>&#x005B;employee&#x005D;
                                                                       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>.&#x2014;Any payment or
                                                                       allowance which the <fnr fntoken="FN_000011" fnrtoken="FNR_000011"
                                                                       >11</fnr>&#x005B;employee&#x005D; 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
                                                                       &#x0028;<emph typestyle="it">a</emph>&#x0029; of the proviso.</text>
                                                                    </p>
                                                                </li>
                                                            </l>
                                                        </li>
                                                        <li>
                                                            <lilabel><fnr fntoken="FN_000012" fnrtoken="FNR_000012"
                                                                >12</fnr>&#x005B;&#x0028;2-A&#x0029;</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.&#x005D;</text>
                                                            </p>
                                                        </li>
                                                        <li>
                                                            <lilabel>&#x0028;3&#x0029;</lilabel>
                                                            <p>
                                                                <text>
                                                                    half-month.&#x005D;</text>
                                                            </p>
                                                        </li>
                                                        <li>
                                                            <lilabel><fnr fntoken="FN_000013" fnrtoken="FNR_000013"
                                                                >13</fnr>&#x005B;&#x0028;4&#x0029;</lilabel>
                                                            <p>
                                                                <text>If the injury of the <fnr fntoken="FN_000011" fnrtoken="FNR_000011"
                                                                    >11</fnr>&#x005B;employee&#x005D; results <fnr fntoken="FN_000014" fnrtoken="FNR_000014"
                                                                       >14</fnr>&#x005B;not less than five thousand 
                                                                    the same to the eldest surviving dependant of the <fnr fntoken="FN_000011"
                                                                       fnrtoken="FNR_000011">11</fnr>&#x005B;employee&#x005D; towards the
                                                                    expenditure of the funeral of such <fnr fntoken="FN_000011"
                                                                       fnrtoken="FNR_000011">11</fnr>&#x005B;employee&#x005D; or where the <fnr
                                                                       fntoken="FN_000011" fnrtoken="FNR_000011">11</fnr>&#x005B;employee&#x005D;
                                                                    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:&#x005D;</text>
                                                            </p>
                                                            <p>
                                                                <text><fnr fntoken="FN_000015" fnrtoken="FNR_000015">15</fnr>&#x005B;Provided that
                                                                    the Central Government may, by notification in the Official Gazette, from time
                                                                    to time, enhance the amount specified in this sub-section.&#x005D;</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>

1 个答案:

答案 0 :(得分:1)

您需要调整xpath。

基本上,您希望在任何ancester中查找这些元素,而不仅仅是根节点的子节点,因此请使用:

for my $sample ( $t->findnodes("//l/li/lilabel") ) {

确保您了解w3school's xpath tutorial

的基本知识