1
Vote

Issue with unknown elements while opening document

description

This Library is currently not managing all objects created in SVG format.
That's why I have met XML level issue while opening a document.
Explanantion:
I try to open a document created with Inkscape containing markers.
Markers will look like this:
    <marker
       inkscape:stockid="Arrow1Lstart"
       orient="auto"
       refY="0.0"
       refX="0.0"
       id="Arrow1Lstart"
       style="overflow:visible"
       inkscape:isstock="true">
      <path
         id="path4162"
         d="M 0.0,0.0 L 5.0,-5.0 L -12.5,0.0 L 5.0,5.0 L 0.0,0.0 z "
         style="fill-rule:evenodd;stroke:#000000;stroke-width:1.0pt"
         transform="scale(0.8) translate(12.5,0)" />
    </marker>
As explained before, "marker" is unknown element for this Library, but not "path" which is a child element of marker.
Because known elements are stacked/unstacked during document opening, in order to manage elements levels, this will lead to exception when you reach next sibling because your stack count will reach 0 !

In order to solve this issue I had to change code in SvgDocument.Open method.
My solution is this:
switch (reader.NodeType)
{
case XmlNodeType.Element:
   ...
   if (element == null)
    {
        //Skip non empty unknown element
        //This is done to avoid any creation of known children of this element in document
        string elementToSkip = reader.LocalName;
        while (elementEmpty == false && reader.Read())
        {
            if (reader.NodeType == XmlNodeType.EndElement 
                && reader.LocalName == elementToSkip)
                break;
        }
        continue;
    }
This simple change will solve the issue.
In addition, you will gain in performance, because unknown children won't be treated by library.

comments