How to retrieve an XML Value using R and the XML library -


i want retrieve xml value "business object" using r

the xml file yed diagram[1]. file shown below

<?xml version="1.0" encoding="utf-8" standalone="no"?> <graphml xmlns="http://graphml.graphdrawing.org/xmlns" xmlns:java="http://www.yworks.com/xml/yfiles-common/1.0/java" xmlns:sys="http://www.yworks.com/xml/yfiles-common/markup/primitives/2.0" xmlns:x="http://www.yworks.com/xml/yfiles-common/markup/2.0" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:y="http://www.yworks.com/xml/graphml" xmlns:yed="http://www.yworks.com/xml/yed/3" xsi:schemalocation="http://graphml.graphdrawing.org/xmlns http://www.yworks.com/xml/schema/graphml/1.1/ygraphml.xsd">   <!--created yed 3.14.2-->   <key attr.name="description" attr.type="string" for="graph" id="d0"/>   <key for="port" id="d1" yfiles.type="portgraphics"/>   <key for="port" id="d2" yfiles.type="portgeometry"/>   <key for="port" id="d3" yfiles.type="portuserdata"/>   <key attr.name="url" attr.type="string" for="node" id="d4"/>   <key attr.name="description" attr.type="string" for="node" id="d5"/>   <key for="node" id="d6" yfiles.type="nodegraphics"/>   <key for="graphml" id="d7" yfiles.type="resources"/>   <key attr.name="url" attr.type="string" for="edge" id="d8"/>   <key attr.name="description" attr.type="string" for="edge" id="d9"/>   <key for="edge" id="d10" yfiles.type="edgegraphics"/>   <graph edgedefault="directed" id="g">     <data key="d0"/>     <node id="n0">       <data key="d5"/>       <data key="d6">         <y:genericnode configuration="com.yworks.bpmn.artifact.withshadow">           <y:geometry height="55.0" width="35.0" x="282.5" y="152.5"/>           <y:fill color="#ffffffe6" transparent="false"/>           <y:borderstyle color="#000000" type="line" width="1.0"/>           <y:nodelabel alignment="center" autosizepolicy="content" fontfamily="dialog" fontsize="12" fontstyle="plain" hasbackgroundcolor="false" haslinecolor="false" height="18.701171875" modelname="custom" textcolor="#000000" visible="true" width="90.70703125" x="-27.853515625" y="-22.701171875">business object<y:labelmodel>               <y:smartnodelabelmodel distance="4.0"/>             </y:labelmodel>             <y:modelparameter>               <y:smartnodelabelmodelparameter labelratiox="0.0" labelratioy="0.5" noderatiox="0.0" noderatioy="-0.5" offsetx="0.0" offsety="-4.0" upx="0.0" upy="-1.0"/>             </y:modelparameter>           </y:nodelabel>           <y:styleproperties>             <y:property class="java.awt.color" name="com.yworks.bpmn.icon.line.color" value="#000000"/>             <y:property class="java.awt.color" name="com.yworks.bpmn.icon.fill2" value="#d4d4d4cc"/>             <y:property class="java.awt.color" name="com.yworks.bpmn.icon.fill" value="#ffffffe6"/>             <y:property class="com.yworks.yfiles.bpmn.view.bpmntypeenum" name="com.yworks.bpmn.type" value="artifact_type_data_object"/>             <y:property class="com.yworks.yfiles.bpmn.view.dataobjecttypeenum" name="com.yworks.bpmn.dataobjecttype" value="data_object_type_plain"/>           </y:styleproperties>         </y:genericnode>       </data>     </node>   </graph>   <data key="d7">     <y:resources/>   </data> </graphml> 

using xmlspy can use the xpath expression //y:nodelabel retrieve result business object!

the r code following

# load libraries library(xml)  path = "./data/" # read yed xml file file.names <- dir(path, pattern ="singlebo.graphml") data <- xmlparse(paste(path, file.names[1], sep=""))  # xpath expression data[["//y:nodelabel"]] 

the result of line data[["//y:nodelabel"]] shown below

<y:nodelabel alignment="center" autosizepolicy="content" fontfamily="dialog" fontsize="12" fontstyle="plain" hasbackgroundcolor="false" haslinecolor="false" height="18.701171875" modelname="custom" textcolor="#000000" visible="true" width="90.70703125" x="-27.853515625" y="-22.701171875">business object<y:labelmodel><y:smartnodelabelmodel distance="4.0"/></y:labelmodel>         <y:modelparameter><y:smartnodelabelmodelparameter labelratiox="0.0" labelratioy="0.5" noderatiox="0.0" noderatioy="-0.5" offsetx="0.0" offsety="-4.0" upx="0.0" upy="-1.0"/></y:modelparameter> </y:nodelabel>  

what need in order retrieve result business object?

all appreciated. john

[1] http://www.yworks.com/en/products_yed_download.html

the easiest thing use xmlvalue()

xmlvalue(data[["//y:nodelabel"]]) # [1] "business object\n            \n          " 

this preserve whitespace , newlines may undesireable. can set trim=true clean selectin

xmlvalue(data[["//y:nodelabel"]], trim=true) # [1] "business object" 

Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -