Validation errors when using XmlReader on XML/SVG files with inline DTDs (Unity/Mono C#)
I am trying to read in an SVG file in C# (Unity/Mono C#) so I can extract the path elements I am interested in. I don't actually want to validate the document. I have even tried ValidationType = ValidationType.None
to no avail.
I keep running into errors and I simply cannot get the file to be validated or skip validation, without modifying the SVG file which I really shouldn't be doing. I thought having a ValidationEventHandler
would stop the code from blocking, but it was not so.
I have checked that the files are valid SVG/XML from the W3C validator and it came up fine.
Error:
XmlSchemaException: XmlSchema error: Element svg is not declared.
or (When I edit the SVG and put a local file in the !DOCTYPE)
XmlSchemaException: XmlSchema error: Attribute value is invalid against its data type 'Mono.Xml.Schema.XsdID'. 'kvg:StrokePaths_0f9ad' is an invalid NCName.
Code:
// Set the validation settings.
XmlReaderSettings settings = new XmlReaderSettings();
settings.XmlResolver = null;
settings.ValidationType = ValidationType.DTD;
settings.ProhibitDtd = false;
settings.ValidationEventHandler += new ValidationEventHandler(ValidationCallBack);
settings.IgnoreWhitespace = true;
// Create the reader
XmlReader reader = XmlReader.Create(path_to_kanji, settings);
//Parse the file.
while (reader.Read())
{
//Extraction of data
}
SVG file:
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2009/2010/2011 Ulrich Apel.
This work is distributed under the conditions of the Creative Commons
Attribution-Share Alike 3.0 Licence. This means you are free:
* to Share - to copy, distribute and transmit the work
* to Remix - to adapt the work
Under the following conditions:
* Attribution. You must attribute the work by stating your use of KanjiVG in
your own copyright header and linking to KanjiVG's website
(http://kanjivg.tagaini.net)
* Share Alike. If you alter, transform, or build upon this work, you may
distribute the resulting work only under the same or similar license to this
one.
See http://creativecommons.org/licenses/by-sa/3.0/ for more details.
-->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd" [
<!ATTLIST g
xmlns:kvg CDATA #FIXED "http://kanjivg.tagaini.net"
kvg:element CDATA #IMPLIED
kvg:variant CDATA #IMPLIED
kvg:partial CDATA #IMPLIED
kvg:original CDATA #IMPLIED
kvg:part CDATA #IMPLIED
kvg:number CDATA #IMPLIED
kvg:tradForm CDATA #IMPLIED
kvg:radicalForm CDATA #IMPLIED
kvg:position CDATA #IMPLIED
kvg:radical CDATA #IMPLIED
kvg:phon CDATA #IMPLIED >
<!ATTLIST path
xmlns:kvg CDATA #FIXED "http://kanjivg.tagaini.net"
kvg:type CDATA #IMPLIED >
]>
<svg xmlns="http://www.w3.org/2000/svg" width="109" height="109" viewBox="0 0 109 109">
<g id="kvg:StrokePaths_0f9ad" style="fill:none;stroke:#000000;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;">
<g id="kvg:0f9ad" kvg:element="玲">
<g id="kvg:0f9ad-g1" kvg:element="王" kvg:original="玉" kvg:partial="true" kvg:position="left" kvg:radical="general">
<path id="kvg:0f9ad-s1" kvg:type="㇐" d="M9.65,28.33c1.53,0.84,5.07,0.34,6.71,0.11c4.56-0.63,10.35-1.83,15.79-2.75c1.41-0.24,3.32-0.74,4.74-0.23"/>
<path id="kvg:0f9ad-s2" kvg:type="㇑a" d="M22.42,30.71c1.06,1.06,1.31,2.04,1.31,3.38c0,4.92,0.04,35.9-0.11,39.17"/>
<path id="kvg:0f9ad-s3" kvg:type="㇐" d="M10.16,51.37c0.49,0.33,3.93,0.35,4.43,0.31C19,51.25,27.5,49.62,32.44,48.7c0.6-0.11,1.93-0.32,3.25-0.09"/>
<path id="kvg:0f9ad-s4" kvg:type="㇐" d="M10.77,78.95c1.03,0.83,2.01,1.11,3.51,0.33c5.6-2.9,10.93-6,18-9.92"/>
</g>
<g id="kvg:0f9ad-g2" kvg:element="令" kvg:position="right">
<g id="kvg:0f9ad-g3" kvg:element="人" kvg:position="top">
<path id="kvg:0f9ad-s5" kvg:type="㇒" d="M62.64,12.75c0.08,0.95,0.13,2.52-0.4,3.83C58.5,25.88,50.38,41.12,39,52.35"/>
<path id="kvg:0f9ad-s6" kvg:type="㇏" d="M62.92,17.79c8.4,8.61,15.21,17.33,24.47,26.71c2.09,2.12,5.1,4.24,7.37,5.63"/>
</g>
<g id="kvg:0f9ad-g4" kvg:position="bottom">
<g id="kvg:0f9ad-g5" kvg:element="一">
<path id="kvg:0f9ad-s7" kvg:type="㇐" d="M50.9,46.1c1.76,0.72,3.84,0.36,5.65,0.14c5.4-0.66,13.08-1.76,18.48-2.24c1.88-0.17,3.54-0.23,5.37,0.21"/>
</g>
<g id="kvg:0f9ad-g6" kvg:element="卩" kvg:original="マ">
<path id="kvg:0f9ad-s8" kvg:type="㇆" d="M51.4,54.6c0.61,0.15,3,1,4.21,0.87c3.29-0.37,17.99-4.02,19.51-4.17c1.52-0.15,4.28-0.29,3.95,2.89c-0.43,4.17-2.68,16.92-6,23.84c-1.89,3.94-3.18,3.45-6.23,0.46"/>
<path id="kvg:0f9ad-s9" kvg:type="㇑" d="M58.58125,55.567708 c 0.87,0.87 1.8,2 1.8,3.5 -0.219826,13.545146 0.202719,23.466557 -0.18,37.006667"/>
</g>
</g>
</g>
</g>
</g>
<g id="kvg:StrokeNumbers_0f9ad" style="font-size:8;fill:#808080">
<text transform="matrix(1 0 0 1 3.60 28.25)">1</text>
<text transform="matrix(1 0 0 1 15.25 39.25)">2</text>
<text transform="matrix(1 0 0 1 3.25 52.25)">3</text>
<text transform="matrix(1 0 0 1 3.25 81.25)">4</text>
<text transform="matrix(1 0 0 1 54.25 15.25)">5</text>
<text transform="matrix(1 0 0 1 69.25 22.25)">6</text>
<text transform="matrix(1 0 0 1 53.7 44)">7</text>
<text transform="matrix(1 0 0 1 44.6 58.1)">8</text>
<text transform="matrix(1 0 0 1 62.5 63)">9</text>
</g>
</svg>
[2]: https://i.stack.imgur.com/AzYTs.png
Your answer
Follow this Question
Related Questions
Namespace using Unity.VectorGraphics not available to scripts 0 Answers
NullReferenceException with XML Deserializer 0 Answers
Getting Questions and Answers from XML file and applying them to the UI 2 Answers
XML Save transform position 1 Answer
Loading xml on android . Tried and it Works in windows... Help ? 0 Answers