4

I need to add a "!ENTITY" field to my document but I can't seem to find the right way to do it. Basically my code currently produces the following result :

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" >
<svg/>

While the result I want is this one :

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" [
    <!ENTITY ns_svg "http://www.w3.org/2000/svg">
    <!ENTITY ns_xlink "http://www.w3.org/1999/xlink">
]>
</svg>

My current code is this :

procedure TSVGContainer.SaveToFile(Filename: String);
var XMLDoc: IXMLDocument;
    DomImpl: IDOMImplementation;
    DocType : IDOMDocumentType;
begin
  XMLDoc := NewXMLDocument;
  DomImpl := GetDOM(sAdom4XmlVendor);
  XMLDoc.Encoding := 'utf-8';
  DocType := DomImpl.createDocumentType('svg', '-//W3C//DTD SVG 1.1//EN', 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd');
  XMLDoc.DOMDocument := DomImpl.createDocument('http://www.w3.org/2000/svg', 'svg', DocType);
  XMLDoc.Options := XMLDoc.Options+[doNodeAutoIndent];
  XMLDoc.SaveToFile(Filename);
end;
AMoraru
  • 41
  • 2
  • 1
    I don't find a way to specify the internal subset on the doctype node. Java and C# seem to have a way to write the internal subset. What you can do is create the document from string. eg Xml := 'needed xml'; xmldoc := loadxmldata(xml); – whosrdaddy Mar 19 '20 at 17:05
  • @whosrdaddy yes, I already saw while searching the web that Java and C# allow you to add an element to the subset, that's why I asked this question. I thought that maybe i missed something. – AMoraru Mar 19 '20 at 17:46
  • I want to be able to add multiple subnodes to my svg node by using the AddChild and AddAttribute methods, I would prefer to avoid writing everything manually into a stringlist and loading into the XML property of the document if possible. – AMoraru Mar 19 '20 at 22:13
  • 1
    Personally I would ingest the doctype and its entities from string and then add nodes to the svg root via code. Or you could make a wrapper C# DLL... – whosrdaddy Mar 20 '20 at 10:18
  • @whosrdaddy Yes, after trying some more yesterday i reached the same conclusion, I'll write the doctype part from string and populate the svg root from code.. If you want to write it as an answer I'll accept it, thank you for your help – AMoraru Mar 20 '20 at 14:15
  • np. Leave the question as is, maybe someone will post a real solution ;) – whosrdaddy Mar 20 '20 at 14:16

0 Answers0