Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.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
如何在R中读取xml的特定属性_R_Xml - Fatal编程技术网

如何在R中读取xml的特定属性

如何在R中读取xml的特定属性,r,xml,R,Xml,下面是我需要解析的示例XML文件。这只是文件的一部分,原始文件非常大。但是格式总是一样的 我只想解析这些值并将其放入数据帧中 <Property Name="Entity1ID" Type="Edm.String"> <Annotation Term="test.Label"> <String>IDENTIFIER</String> </Annotation> </Property

下面是我需要解析的示例XML文件。这只是文件的一部分,原始文件非常大。但是格式总是一样的

我只想解析这些值并将其放入数据帧中

<Property Name="Entity1ID" Type="Edm.String">
      <Annotation Term="test.Label">
             <String>IDENTIFIER</String>
      </Annotation>
</Property>
等等

大约有10个EntityType和1000个属性标记,我只需要解析属性标记并映射值

我无法解析这些值。我知道这将是一个小计划,但我是新的R

提前谢谢

<edmx:Edmx xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx" Version="4.0">
    <edmx:Data>
        <Schema xmlns="http://docs.oasis-open.org/odata/ns/edm" Namespace="test.Models" Alias="test">
            <EntityType Name="Entity1">
                <Key>
                    <PropertyRef Name="ID"/>
                </Key>
                <Property Name="Entity1ID" Type="Edm.String">
                    <Annotation Term="test.Label">
                        <String>IDENTIFIER</String>
                    </Annotation>
                </Property>
                <Property Name="ID" Type="Edm.String">
                    <Annotation Term="test.Label">
                        <String>FILEID</String>
                    </Annotation>
                </Property>
                <NavigationProperty Name="Subjects" Type="Collection(test.Subjects)"/>

            </EntityType>
            <EntityType Name="Entity2">
                <Key>
                    <PropertyRef Name="Entity2ID"/>
                </Key>
                <Property Name="Entity2ID" Type="Edm.String">
                    <Annotation Term="test.Label">
                        <String>ID</String>
                    </Annotation>
                </Property>
            </EntityType>
            <Function Name="GetData" EntitySetPath="asphalt/Entity2" IsBound="true">
                <Parameter Name="asphalt" Type="test.asphalt" Nullable="false"/>
                <Parameter Name="ID" Type="Edm.String"/>
                <ReturnType Type="Collection(test.Entity2)" Nullable="false"/>
            </Function>

            <Term Name="Label" Type="Edm.String"/>
            <EntityContainer Name="API">
                <EntitySet Name="Studies" EntityType="test.Entity1"/>
            </EntityContainer>
        </Schema>
    </edmx:Data>
</edmx:Edmx>

标识符
文件ID
身份证件
希望这有帮助

库(xml2)
图书馆(dplyr)
#test.xml是包含xml数据的文件
xml_doc%
xml_text()
关键%
xml\u find\u all(“//edmx:Data/d1:Schema/d1:EntityType/d1:Property”,ns=xml\ns(xml\u doc))%>%
xml_属性(“名称”)

df您尝试了什么不起作用的?“谢谢您的努力:)很高兴它起了作用:)
<edmx:Edmx xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx" Version="4.0">
    <edmx:Data>
        <Schema xmlns="http://docs.oasis-open.org/odata/ns/edm" Namespace="test.Models" Alias="test">
            <EntityType Name="Entity1">
                <Key>
                    <PropertyRef Name="ID"/>
                </Key>
                <Property Name="Entity1ID" Type="Edm.String">
                    <Annotation Term="test.Label">
                        <String>IDENTIFIER</String>
                    </Annotation>
                </Property>
                <Property Name="ID" Type="Edm.String">
                    <Annotation Term="test.Label">
                        <String>FILEID</String>
                    </Annotation>
                </Property>
                <NavigationProperty Name="Subjects" Type="Collection(test.Subjects)"/>

            </EntityType>
            <EntityType Name="Entity2">
                <Key>
                    <PropertyRef Name="Entity2ID"/>
                </Key>
                <Property Name="Entity2ID" Type="Edm.String">
                    <Annotation Term="test.Label">
                        <String>ID</String>
                    </Annotation>
                </Property>
            </EntityType>
            <Function Name="GetData" EntitySetPath="asphalt/Entity2" IsBound="true">
                <Parameter Name="asphalt" Type="test.asphalt" Nullable="false"/>
                <Parameter Name="ID" Type="Edm.String"/>
                <ReturnType Type="Collection(test.Entity2)" Nullable="false"/>
            </Function>

            <Term Name="Label" Type="Edm.String"/>
            <EntityContainer Name="API">
                <EntitySet Name="Studies" EntityType="test.Entity1"/>
            </EntityContainer>
        </Schema>
    </edmx:Data>
</edmx:Edmx>
        Key      Value
1 Entity1ID IDENTIFIER
2        ID     FILEID
3 Entity2ID         ID