R : Parsing XML to a desired mapping table -
I have XML with sample format, and need to prepare a mapping table.
& lt; Parameter & gt; & Lt; Ultimate Suffix = "1" & gt; A & lt; / Ultimate & gt; & Lt; Ultimate Suffix = "2" & gt; B & lt; / Ultimate & gt; & Lt; Ultimate Suffix = "3" & gt; C & lt; / Ultimate & gt; & Lt; Ultimate Suffix = "4" & gt; D & lt; / Ultimate & gt; & Lt; Ultimate Suffix = "5" & gt; E & lt; / Ultimate & gt; & Lt; Parameter & gt;
Desire is production: Ultimate value (A, B, C ...) is mapped to a composite ultimate & amp; Suffix (A_1, B_2, C_3 ...)
A -> A_1b - & gt; B2C - & gt; C_3 D - & gt; D_4 E - & gt; E_5
Any kind of formatting will be done, as long as I can get the parmList ["A"] like A_1 Proceed.
Something like this:
Library (xml) xmltest & lt; - "& lt; parameter> gt; & lt; parm suffix = \" 1 \ "& gt; & lt; / parm & gt; & lt; parm suffix = \" 2 \ "& gt; B & lt; / Parm & gt; & lt; parm suffix = \ "3 \" & gt; c & lt; / parm & gt; & lt; parm suffix = \ "4 \" & gt; d & lt; / parm & gt; & Lt; parm suffix = \ "5 \" & gt; E & lt; / parm> gt; & lt; / parameter & gt; Xmlout & lt; - xmlInternalTreeParse (xmltest) outattrs & lt; - xpathApply (xmlout, "// parameter / parm", xmlGetAttr, "suffix") outval & lt; - xpathApply (xmlout, "// parameter / parm", xmlValue) parmList & lt; - Setmen (map (paste, outwal, outats, Sep = "_"), outlaw) # $ A # [1] "A4" # $ B # [1] "B2" # $ C # [1] CFO "# $ D # [1]" D_4 "# $ E # [1]" E_5 "Permalink [[" A "]] # [1]" A4 "
Comments
Post a Comment