i have saved multiple xml files within 1 giant xml file and nowwhen i parse it u
ID: 3609286 • Letter: I
Question
i have saved multiple xml files within 1 giant xml file and nowwhen i parse it using perl am getting an error which says junkelement.is there any way that i can parse multiple xml files withperl?my file(a small clip):
<?xml version="1.0"?><!DOCTYPE eSummaryResult PUBLIC"-//NLM//DTD eSummaryResult, 29 October 2004//EN""http://www.ncbi.nlm.nih.gov/entrez/query/DTD/eSummary_041029.dtd"><eSummaryResult><DocSum> <Id>6197</Id> <ItemName="CID" Type="Integer">6197</Item> <Item Name="SourceNameList"Type="List"></Item> <ItemName="SourceIDList" Type="List"></Item> <Item Name="SourceCategoryList"Type="List"> <ItemName="string" Type="String">SubstanceVendors</Item> <ItemName="string" Type="String">MetabolicPathways</Item> </docsum></eSummaryResult>
<?xml version="1.0"?><!DOCTYPE eSummaryResult PUBLIC"-//NLM//DTD eSummaryResult, 29 October 2004//EN""http://www.ncbi.nlm.nih.gov/entrez/query/DTD/eSummary_041029.dtd"><eSummaryResult><DocSum> <Id>6197</Id> <Item Name="CID"Type="Integer">6197</Item> <ItemName="SourceNameList"Type="List"></Item> <ItemName="SourceIDList" Type="List"></Item> <Item Name="SourceCategoryList"Type="List"> <ItemName="string" Type="String">SubstanceVendors</Item> <ItemName="string" Type="String">MetabolicPathways</Item> </docsum></eSummaryResult>
Explanation / Answer
You will not able to parse it as a single xml since there ismultiple xml header. There are several way to dealing withthis. One is you need to format it into a legal xml filebefore save it into the gaint file. Which should be somethinglike: <?xml version="1.0"?><!DOCTYPE eSummaryResult PUBLIC"-//NLM//DTD eSummaryResult, 29 October 2004//EN""http://www.ncbi.nlm.nih.gov/entrez/query/DTD/eSummary_041029.dtd"> <ResultList> <eSummaryResult>...</eSummaryResult><eSummaryResult>...</eSummaryResult>
</ResultList> If you don't have control about how the file is written. Buthave to read it. Then you will need to read each individulexml block into a string and parse it seperately. Hope that make sense,
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.