cocoa-touchsvgsvgkit

SVGKit: how to split one .svg file into several UIView?


How can how explore a .svg file with SVGKit?

I have issues splitting one .svg file into several UIView.

What I have tried

Here is what I have done so far. If you have any clue on how I should proceed, thank you!

  1. I created a .svg file. I gave the name "AAAA" to one of the two objects. enter image description here

  2. I add the .svg file to my project.

  3. Then, I use SVGKit to explore my .svg file, with the following code:

code:

 SVGKImage* newImage = [SVGKImage imageNamed:@"Untitled-1"];

 NSString* tagToFind = @"AAAA";
 NodeList* result = [newImage.DOMDocument getElementsByTagName:tagToFind];

 for( Element* domElement in result )
 {
     SVGElement* svgElement = (SVGElement*) domElement;
 }

Problems:

  1. The .svg image is well loaded, and I can display it. This is what works!! But...

  2. the newImage.DOMDocument does not seem to reflect the actual document. Here is what NSLog gives

Node: #document (DOCUMENT) value:[(null)] @@0 attributes + 0 x children

  1. the result array is empty.

Remarks

I have created the .svg with Illustrator and then tried to add info on Inkscape. Any solution is ok for me. Here is the .png file.

<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 16.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0)  -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
     width="623.619px" height="481.89px" viewBox="0 0 623.619 481.89" enable-background="new 0 0 623.619 481.89"
     xml:space="preserve">
<g id="AAAA" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:cc="http://creativecommons.org/ns#" xmlns:svg="http://www.w3.org/2000/svg" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" sodipodi:docname="Untitled-1.svg" inkscape:version="0.48.2 r9819">

        <rect id="AAAA_1_" x="482.945" y="43.653" fill="#FF0000" stroke="#000000" stroke-miterlimit="10" width="57.046" height="68.157"/>
</g>
<g id="BBBB_1_">
    <polygon id="BBBB" fill="#2824B3" stroke="#000000" stroke-miterlimit="10" points="579.31,259.945 532.676,261.485 
        507.507,300.775 491.632,256.898 446.488,245.101 483.31,216.445 480.578,169.865 519.213,196.03 562.667,179.039 549.722,223.867 
            "/>
</g>
</svg>

Solution

  • The correct code is

    SVGKImage* newImage = [SVGKImage imageNamed:@"Untitled-1"];
    
    NSString* tagToFind = @"BBBB";
    
    Element* result = [newImage.DOMTree getElementById:tagToFind];