fromGXL-methods            package:graph            R Documentation

_M_e_t_h_o_d_s _f_o_r _G_X_L _m_a_n_i_p_u_l_a_t_i_o_n_s _i_n _p_a_c_k_a_g_e _g_r_a_p_h

_D_e_s_c_r_i_p_t_i_o_n:

     GXL <URL: www.gupro.de/GXL> is "an XML sublanguage designed to be
     a standard exchange format for graphs".  This document describes
     tools in the graph package for importing GXL data to R and for
     writing graph data out as GXL.

_V_a_l_u_e:

 fromGXL: currently returns a graphNEL when possible.  This function is
          based on xmlEventParse with handlers defined in the function
          NELhandler.  The dump() element of this handler should emit
          information on all children of nodes and edges; the
          asGraphNEL() element will return a graphNEL object with
          weights if child <attr> with name attribute "weights" is
          present for each edge element.

   toGXL: for an input of class "graphNEL", returns an object of class
          c("XMLInternalDOM", "XMLOutputStream"); see the example for
          how to convert this to a text stream encoding XML

 dumpGXL: returns an R list with all the node, edge, and named
          attribute information specified in the GXL stream

validateGXL: returns silently (invisibly returns the parsed tree) for a
          DTD-compliant stream, or is otherwise very noisy

_M_e_t_h_o_d_s:

     _f_r_o_m_G_X_L con = connection: returns a graphNEL based on a parsing of
          the GXL stream on the connection 

     _d_u_m_p_G_X_L con = connection: returns an R list based on a parsing of
          the GXL stream on the connection 

     _v_a_l_i_d_a_t_e_G_X_L con = connection: checks the GXL stream against its
          DTD

     _t_o_G_X_L object = graphNEL: creates an XMLInternalDOM representing
          the graph in GXL

_N_o_t_e:

     At present, toGXL does not return a validating GXL stream because
     XML package does not properly handle the dtd and namespaces
     arguments to xmlTree.  This is being repaired.  To fix the stream,
     add ' <!DOCTYPE gxl SYSTEM
     "http://www.gupro.de/GXL/gxl-1.0.1.dtd"> ' as second record in the
     output.

     Some structures in a graphNEL and some tags in GXL may not be
     handled at this time.

_A_u_t_h_o_r(_s):

     Vince Carey <stvjc@channing.harvard.edu>

_E_x_a_m_p_l_e_s:

     sf <- file(system.file("GXL/simpleExample.gxl", package="graph"))
     show(fromGXL(sf))
     print(dumpGXL(sf))
     close(sf)
     #validateGXL(sf)
     # bad <- file(system.file("GXL/c2.gxl", package="graph"))
     # here's how you can check if the GXL is well-formed, if
     # you have a libxml2-based version of R XML package
     #
     # try( validateGXL(bad) )
     #
     gR <- new("graphNEL", nodes=letters[1:4], edgeL=list(
      a=list(edges=4), b=list(edges=3), c=list(edges=c(2,1)), d=list(edges=1)),
      edgemode="directed")
     #
     # following requires that you are using XML bound with recent libxml2
     #
     #an <- as.numeric
     #if (an(libxmlVersion()$major)>=2 && an(libxmlVersion()$minor)>=4)
       cat(saveXML(toGXL(gR)$value()))
     wtd <- file(system.file("GXL/kmstEx.gxl", package="graph"))
     wtdg <- fromGXL(wtd)
     close(wtd)
     print(edgeWeights(wtdg))

