我不熟悉将XML文件导入R. 我已经查看了有关此主题的现有问题,但找不到一个似乎合适的问题。我很感谢你的评论!
我的问题如下: 我有一个具有以下结构的XML文件
<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
<PublicationData>
<Products numberOfProducts="2094">
<Product terminationReason="" isSalePermission="false" soldoutDeadline="" exhaustionDeadline="" name="Résanol Trio " wNbr="6016" id="7034">
<ProductInformation>
<ProductCategory primaryKey="7282"/>
<ProductCategory primaryKey="7282"/>
<FormulationCode primaryKey="6486"/>
<DangerSymbol primaryKey="6513"/>
<DangerSymbol primaryKey="6509"/>
<CodeS primaryKey="6145"/>
<CodeS primaryKey="6117"/>
<CodeS primaryKey="6039"/>
<CodeS primaryKey="6057"/>
<CodeS primaryKey="6066"/>
<CodeS primaryKey="6106"/>
<CodeS primaryKey="6076"/>
<CodeS primaryKey="6088"/>
<CodeR primaryKey="5977"/>
<CodeR primaryKey="5943"/>
<CodeR primaryKey="5945"/>
<CodeR primaryKey="5948"/>
<CodeR primaryKey="6020"/>
<PermissionHolderKey primaryKey="10115"/>
<Ingredient additionalTextPrimaryKey="" inGrammPerLitre="" inPercent="7.5">
<SubstanceType xsi:type="xs:string" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">ACTIVE_INGREDIENT</SubstanceType>
<Substance primaryKey="898"/>
</Ingredient>
<Ingredient additionalTextPrimaryKey="" inGrammPerLitre="" inPercent="40.0">
<SubstanceType xsi:type="xs:string" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">ACTIVE_INGREDIENT</SubstanceType>
<Substance primaryKey="338"/>
</Ingredient>
<Ingredient additionalTextPrimaryKey="" inGrammPerLitre="" inPercent="15.0">
<SubstanceType xsi:type="xs:string" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">ACTIVE_INGREDIENT</SubstanceType>
<Substance primaryKey="190"/>
</Ingredient>
<Indication expenditureTo="" expenditureForm="8.0" waitingPeriod="" dosageTo="" dosageFrom="0.5">
<Measure primaryKey="6518"/>
<ApplicationArea primaryKey="3"/>
<ApplicationComment primaryKey="868"/>
<Culture additionalTextPrimaryKey="" primaryKey="9953"/>
<Pest type="PEST_FULL_EFFECT" additionalTextPrimaryKey="" primaryKey="10506"/>
<Pest type="PEST_FULL_EFFECT" additionalTextPrimaryKey="6964" primaryKey="10508"/>
<Pest type="PEST_FULL_EFFECT" additionalTextPrimaryKey="" primaryKey="10507"/>
<Pest type="PEST_PARTIAL_EFFECT" additionalTextPrimaryKey="" primaryKey="10533"/>
<Obligation primaryKey="12317"/>
<Obligation primaryKey="11380"/>
<Obligation primaryKey="9156"/>
<Obligation primaryKey="9735"/>
<Obligation primaryKey="9906"/>
</Indication>
</ProductInformation>
</Product>
我正在尝试提取&#34; ProductInformation&#34;节点并尝试
xmlfile<-xmlParse("filepath")
relevant<-xpathApply(xmlfile,"//*/Products/Product")
relevant2<-sapply(relevant,xmlValue)
这给了我类似的东西
[1] "ACTIVE_INGREDIENTACTIVE_INGREDIENT"
[...] "ACTIVE_INGREDIENT"
[2094] "ACTIVE_INGREDIENT"
改为使用
relevant2<-sapply(relevant,xmlAttrs)
如果也无法提取信息。
我的问题的答案可能很明显,但我无法找到答案。谢谢你的帮助!