使用R从xml文件中提取多个值

使用R从xml文件中提取多个值,r,xml,R,Xml,下面是我正在使用的XML文件的一个小示例。我想提取卖家评级超过150的拍卖数量。有人知道我是怎么做的吗 <root> <listing> <seller_info> <seller_name>seller12</seller_name> <seller_rating>100</seller_rating>

下面是我正在使用的XML文件的一个小示例。我想提取卖家评级超过150的拍卖数量。有人知道我是怎么做的吗

<root>
        <listing>
            <seller_info>
                <seller_name>seller12</seller_name>
                <seller_rating>100</seller_rating>
            </seller_info>
            <payment_types>
                Visa
            </payment_types>
            <shipping_info>
                Buyer pays shipping charges.
            </shipping_info>
            <buyer_protection_info></buyer_protection_info>
            <auction_info>
                <current_bid>$820.00</current_bid>
                <time_left>4 days, 18 hours +</time_left>
                <high_bidder>
                    <bidder_name>gosha555@example.com</bidder_name>
                    <bidder_rating>-2</bidder_rating>
                </high_bidder>
                <num_items>1</num_items>
                <num_bids>12</num_bids>
                <started_at>$1.00</started_at>
                <bid_increment></bid_increment>
                <notes></notes>
            </auction_info>
        </listing>
        <listing>
            <seller_info>
                <seller_name>seller50</seller_name>
                <seller_rating>200</seller_rating>
            </seller_info>
            <payment_types>
                Visa
            </payment_types>
            <shipping_info>
                Buyer pays shipping charges.
            </shipping_info>
            <buyer_protection_info></buyer_protection_info>
            <auction_info>
                <current_bid>$920.00</current_bid>
                <time_left>4 days, 17 hours +</time_left>
                <high_bidder>
                    <bidder_name>seller50@example.com</bidder_name>
                    <bidder_rating>-2</bidder_rating>
                </high_bidder>
                <num_items>1</num_items>
                <num_bids>5</num_bids>
                <started_at>$1.00</started_at>
                <bid_increment></bid_increment>
                <notes></notes>
            </auction_info>
        </listing>  
<root>

我看到你的代码也得到了标签。如果您使用:

SellerRatings = xmlSApply(doc["//listing//seller_info//seller_rating"], xmlValue)
您只需获取值,就可以对其进行计数

sum(SellerRatings > 150)
或者短暂地

sum(xmlSApply(doc["//*//seller_rating"], xmlValue) > 150)

那么,您尝试的代码有什么问题?那么期望的结果是什么?@Parfait问题是我提取了所有卖家评级的拍卖,而不仅仅是卖家评级超过150的拍卖。我只想输出卖家评级>150Thank@G5W的拍卖数量。当我尝试您的代码时,我得到了以下错误:
error in UseMethod(“xpathApply”):没有适用于“xpathApply”类的对象的方法应用于“XMLNodeSet”
它是XPath如果它有一个Sweird,我使用的是S.
doc Doh。我没有仔细阅读。NOT
xpathsaply
应该是
xmlsaply
sum(xmlSApply(doc["//*//seller_rating"], xmlValue) > 150)