https://github.com/cran/XML
Tip revision: 6ac5aacfa6b8250c6501b2fe1c24fc9f287f02f3 authored by Duncan Temple Lang on 29 April 2011, 00:00:00 UTC
version 3.4-0
version 3.4-0
Tip revision: 6ac5aac
compare.R
# For comparing if two XML documents are "similar" whatever that means.
# We look at the distribution of node names
summary.XMLInternalDocument =
function(object, ...)
{
counts = sort(table(xpathSApply(object, "//*", xmlName, ...)), decreasing = TRUE)
list(nameCounts = counts,
numNodes = sum(counts))
}
compareXMLDocs =
function(a, b, ...)
{
sa = summary(a, ...)
sb = summary(b, ...)
inAOnly = setdiff(names(sa$nameCounts), names(sb$nameCounts))
inBOnly = setdiff(names(sb$nameCounts), names(sa$nameCounts))
common.ids = intersect(names(sa$nameCounts), names(sb$nameCounts)) # != sb$nameCounts[names(sa$nameCounts)
diffs = sa$nameCounts[common.ids] - sb$nameCounts[common.ids]
diffs = diffs[diffs != 0]
list(inA = sa$nameCounts[inAOnly], inB = sb$nameCounts[inBOnly], countDiffs = diffs)
#all.equal(sa, sb)
}