Ho un file XML grande che ho bisogno di analizzare con xmlEventParse in R. Purtroppo on-line esempi sono più complessi di quanto ho bisogno, e voglio solo la bandiera di un tag corrispondente nodo per memorizzare il testo del nodo corrispondente (non attribuire), ogni testo in un elenco separato, vedere i commenti nel codice qui sotto:memorizzare i valori specifici del nodo XML con xmlEventParse di R
library(XML)
z <- xmlEventParse(
"my.xml",
handlers = list(
startDocument = function()
{
cat("Starting document\n")
},
startElement = function(name,attr)
{
if (name == "myNodeToMatch1"){
cat("FLAG Matched element 1\n")
}
if (name == "myNodeToMatch2"){
cat("FLAG Matched element 2\n")
}
},
text = function(text) {
if (# Matched element 1 ....)
# Store text in element 1 list
if (# Matched element 2 ....)
# Store text in element 2 list
},
endDocument = function()
{
cat("ending document\n")
}
),
addContext = FALSE,
useTagName = FALSE,
ignoreBlanks = TRUE,
trim = TRUE)
z$ ... # show lists ??
la mia domanda è, come implementare questo flag in R (in modo professionale :)? Plus: Qual è la scelta migliore per valutare N nodi arbitrari da abbinare ... se name = "myNodeToMatchN" ... nodi che evitino la corrispondenza dei casi?
my.xml potrebbe essere solo un XML ingenua come
<A>
<myNodeToMatch1>Text in NodeToMatch1</myNodeToMatch1>
<B>
<myNodeToMatch2>Text in NodeToMatch2</myNodeToMatch2>
...
</B>
</A>
Sarebbe bello se avessimo a portata di mano "my.xml" per provare ... –