# Parsing SVG file

**URL:** <https://discourse.processing.org/t/parsing-svg-file/13991>\
**Category:** Coding Questions\
**Created:** [September 14, 2019, 5:32pm UTC](https://discourse.processing.org/t/parsing-svg-file/13991 "2019-09-14T17:32:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![eduzal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/eduzal/32/759_2.png) [@eduzal](https://discourse.processing.org/u/eduzal)\
**Post date:** [September 14, 2019, 5:32pm UTC](https://discourse.processing.org/t/parsing-svg-file/13991/1 "2019-09-14T17:32:49Z")

</div>

I have this svg

```auto
<g id="Layer_1">
	<path style="fill:none;stroke:#FA8B00;stroke-width:4;stroke-linecap:round;stroke-miterlimit:10;" d="M1272.8,558l19.2,20l-49,81
		l-18-19L1272.8,558z"/>

```

how do i access style properties, like color and strokeWeight, parse it in my proper variables and make it something i can use?

my objective is to be able to load an svg file, modify it, add other elements to it than save afterwards.

---

<div class="post-metadata">

**Author:** ![eduzal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/eduzal/32/759_2.png) [@eduzal](https://discourse.processing.org/u/eduzal)\
**Post date:** [September 14, 2019, 7:46pm UTC](https://discourse.processing.org/t/parsing-svg-file/13991/2 "2019-09-14T19:46:35Z")

</div>

it neeeded a lot of digging but finally have the solution

```auto
void buildShape() {
  println("loading svg");
  original=loadShape(svgFile);
  println("loading XML");
  XML xml=loadXML(svgFile);
  println("parsing XML Children");
  XML[] xmlChildren=xml.getChildren();
  //printArray(xmlChildren);

  //original.disableStyle();
  int numChild=original.getChildCount();
  println("numLayers: "+numChild);

  for (int i=0; i<numChild; i++) {
    PShape tempFace=original.getChild(i);
    XML tempFaceXML=xmlChildren[i+1+i];
    //printArray("tempFaceXML: "+tempFaceXML);
    int numBricks=tempFace.getChildCount();
    println("face: "+i+" numBricks:"+numBricks);

    for (int j=0; j<numBricks; j++) {
      println("face: "+i+" get Brick:"+j);
      PShape temp=tempFace.getChild(j);
      XML tempXML=tempFaceXML.getChild(j+1+j);
      println("tempXML: "+tempXML);
      String style=tempXML.getString("style");
      println("style: "+style);
      String[] styleData=splitTokens(style, "; :");

      println("styleData color: "+styleData[3]);//strokeColor
      println("styleData strokeWeight: "+styleData[5]);//strokeWeight
      color c=unhex("FF"+styleData[3].substring(1));

      pLines.add(new Polyline(c, int(styleData[5])));

      int vCount=temp.getVertexCount();

      for (int k=0; k<vCount; k++) {
        Polyline p=pLines.get(pLines.size()-1);
        PVector pv=temp.getVertex(k);
        p.addVertex(int(pv.x), int(pv.y));
      }
    }
  }
}
```
