Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.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中的两步转换?_Xml_R_Markup - Fatal编程技术网

如何使用R处理XML中的两步转换?

如何使用R处理XML中的两步转换?,xml,r,markup,Xml,R,Markup,我正在使用R xml包解析一个xml。XML具有以下标记 < &lt; > &gt; & &amp; Input Text: My age is &amp;gt; 65 years years. output: My age is gt;65 years. 您可以编写这样的函数 batchgsub <- function(patternmatrix, string) { for (

我正在使用R xml包解析一个xml。XML具有以下标记

 <  &lt;
 >  &gt;
 &  &amp;

Input Text: 
       My age is &amp;gt; 65 years years. 

       output: My age is gt;65 years.

您可以编写这样的函数

batchgsub <- function(patternmatrix, string) {
    for (i in 1:nrow(patternmatrix)) {
        p = patternmatrix[i,1]
        r = patternmatrix[i,2]
        string <- gsub(p,r,string)
    }
    return(string)
}
> pm
     [,1]    [,2]
[1,] "&amp;" "&" 
[2,] "&gt;"  ">" 
然后,您可以根据需要多次链接替换

> s <- "My age is &amp;gt; 65 years."
> batchgsub(pm, s)
[1] "My age is > 65 years."

我需要标准的软件包来阅读这篇文章并自动转换。我可以理解,并不是每个人都把英语作为第一语言,但我不明白你在问什么。这是依赖于“基本”包的代码。你不能得到比这更高的标准。
> pm
     [,1]    [,2]
[1,] "&amp;" "&" 
[2,] "&gt;"  ">" 
> s <- "My age is &amp;gt; 65 years."
> batchgsub(pm, s)
[1] "My age is > 65 years."