KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Exporting SVG picture to XML
PRODUCT: 4D | VERSION: 16 | PLATFORM: Mac & Win
Published On: August 1, 2017

Here is a utility to export an SVG picture that is created in 4D to XML:

// -----------------------------------------------------------------------
// Name: EXPORT_SVG_PICTURE_TO_XML
// Description: Takes in a graph picture that is SVG format and exports
// it to XML by text variable or file.
// Parameter:
// $1 (PICTURE) - Graph picture variable to import.
// $2 (TEXT) - Location of the XML file to save.
// Output:
// $0 (TEXT) - XML export text or not returned if a file loc is provided.
// -----------------------------------------------------------------------
C_PICTURE($1;$pictData)
C_TEXT($2;$textLocXML)
C_TEXT($0;$svg_id;$textXML)

If (Count parameters=1)
    $pictData:=$1
   
    $svg_id:=SVG_Open_picture ($pictData)
    DOM EXPORT TO VAR($svg_id;$textXML)
    $0:=$textXML
Else
    $pictData:=$1
    $textLocXML:=$2
   
    $svg_id:=SVG_Open_picture ($pictData)
    DOM EXPORT TO FILE($svg_id;$textLocXML)
End if


Here is example of an SVG Picture:



C_PICTURE(vGraph) //Variable of graph
ARRAY TEXT(X;2) //Create an array for the x-axis
X{1}:="1995" //X Label #1
X{2}:="1996" //X Label #2
ARRAY REAL(A;2) //Create an array for the y-axis
A{1}:=30 //Insert some data
A{2}:=40
ARRAY REAL(B;2) //Create an array for the y-axis
B{1}:=50 //Insert some data
B{2}:=80
GRAPH(vGraph;2;X;A;B) //Draw the graph
GRAPH SETTINGS(vGraph;0;0;0;0;False;False;True;"France";"USA") //Set the legends for the graph


Example #1: To return the XML as text:

C_TEXT($exportText)
$exportText:=EXPORT_SVG_PICTURE_TO_XML (vGraph)


Example #2: To save the XML in a ".xml" file:

C_TEXT($loc)
$loc:=get 4d folder(Database folder)+"exportedXML.xml"
EXPORT_SVG_PICTURE_TO_XML (vGraph;$loc)