Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用PerlXML::LibXML解析XML_Xml_Perl_Xml Libxml - Fatal编程技术网

使用PerlXML::LibXML解析XML

使用PerlXML::LibXML解析XML,xml,perl,xml-libxml,Xml,Perl,Xml Libxml,我有一个Web服务,它以以下格式返回XML。我正在使用XML::LibXML解析输出 <QueryResponse xmlns="http://www.exchangenetwork.net/schema/node/2" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"> <LastSet>true</LastSet> <Results> <SRS:Subs

我有一个Web服务,它以以下格式返回XML。我正在使用XML::LibXML解析输出

<QueryResponse xmlns="http://www.exchangenetwork.net/schema/node/2" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
    <LastSet>true</LastSet>
    <Results>
        <SRS:SubstanceInformation xsi:schemaLocation="http://www.exchangenetwork.net/schema/SRS/3 http://www.exchangenetwork.net/schema/SRS/3" xmlns:SRS="http://www.exchangenetwork.net/schema/SRS/3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            <SRS:ChemicalSubstance>
                <SRS:ChemicalSubstanceIdentification>
                    <SRS:EPAChemicalInternalNumber>76109</SRS:EPAChemicalInternalNumber>
                    <SRS:CASRegistryNumber>1000-82-4</SRS:CASRegistryNumber>
                    <SRS:ChemicalSubstanceSystematicName>Urea, N-(hydroxymethyl)-</SRS:ChemicalSubstanceSystematicName>
                    <SRS:EPAChemicalRegistryName>Methylolurea</SRS:EPAChemicalRegistryName>
                    <SRS:EPAChemicalIdentifier/>
                    <SRS:ChemicalSubstanceDefinitionText/>
                    <SRS:ChemicalSubstanceCommentText/>
                    <SRS:MolecularFormulaCode>C2H6N2O2</SRS:MolecularFormulaCode>
                    <SRS:ChemicalSubstanceFormulaWeightQuantity>90.08</SRS:ChemicalSubstanceFormulaWeightQuantity>
                    <SRS:ChemicalSubstanceLinearStructureCode>O=C(NCO)N</SRS:ChemicalSubstanceLinearStructureCode>
                    <SRS:InternationalChemicalIdentifier/>
                    <SRS:FormerCASRegistryNumberList/>
                    <SRS:IncorrectlyUsedCASRegistryNumberList>
                        <SRS:CASRegistryNumber>50-00-0</SRS:CASRegistryNumber>
                    </SRS:IncorrectlyUsedCASRegistryNumberList>
                    <SRS:ClassificationList/>
                    <SRS:TechnicalPointOfContact/>
                    <SRS:SubstanceRequestor/>
                    <SRS:SubstanceCreateDate>2006-10-13 14:30:12.0</SRS:SubstanceCreateDate>
                    <SRS:SubstanceLastUpdateDate>2010-01-20 12:29:21.0</SRS:SubstanceLastUpdateDate>
                    <SRS:SubstanceStatus>A</SRS:SubstanceStatus>
                </SRS:ChemicalSubstanceIdentification>
                <SRS:ChemicalSubstanceSynonymList>
                    <SRS:ChemicalSubstanceSynonym>
                        <SRS:ChemicalSubstanceSynonymName>Urea, (hydroxymethyl)-</SRS:ChemicalSubstanceSynonymName>
                        <SRS:ChemicalSynonymStatusName>Reviewed</SRS:ChemicalSynonymStatusName>
                        <SRS:ChemicalSynonymSourceName>Chemical Update System (CUS) 1986</SRS:ChemicalSynonymSourceName>
                        <SRS:RegulationReasonText/>
                        <SRS:CharacteristicList/>
                        <SRS:AlternateIdentifierList/>
                    </SRS:ChemicalSubstanceSynonym>
                </SRS:ChemicalSubstanceSynonymList>
            </SRS:ChemicalSubstance>
        </SRS:SubstanceInformation>
    </Results>
    <RowCount>1</RowCount>
    <RowId>0</RowId>
</QueryResponse>

是我做的有问题。感谢您的帮助。谢谢

XPath上的前两个元素在
http://www.exchangenetwork.net/schema/node/2
XML文档中的命名空间。您必须为XPath的
QueryResponse
Results
元素指定名称空间

或者,如果在
结果中只有一个
SRS:SubstanceInformation
,您可以通过
/
跳过
QueryResponse
Results

//SRS:SubstanceInformation/SRS:ChemicalSubstance/SRS:ChemicalSubstanceIdentification
//SRS:SubstanceInformation/SRS:ChemicalSubstance/SRS:ChemicalSubstanceIdentification