Coder Social home page Coder Social logo

Support for DTDs? about aexml HOT 4 OPEN

Vithanco avatar Vithanco commented on August 20, 2024
Support for DTDs?

from aexml.

Comments (4)

Vithanco avatar Vithanco commented on August 20, 2024 1

I looked into this. I created the document like this: 

svg = try AEXMLDocument(xml: """        
<?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 version="1.1" xmlns="http://www.w3.org/2000/svg">        
</svg>        
""")

however, when I save this I get only this:

<?xml version="1.0" encoding="utf-8" standalone="no"?>
<svg version="1.1" xmlns="http://www.w3.org/2000/svg"></svg>

AEXMLOptions isn't ready for inheritance, since it is a struct and you didn't use a protocol.
However, I assume you are open for me to change this?. I will send you a pull request.

from aexml.

Vithanco avatar Vithanco commented on August 20, 2024

Maybe I should initiate the document with a root element and a DTD already included?

from aexml.

tadija avatar tadija commented on August 20, 2024

Hi @themadone, I think that extending AEXMLOptions with another subtype for this purpose is a good idea (rather than extending existing DocumentHeader type). I'm not sure if this would affect parsing in some unexpected way, but if not that it should be a simple change. Creating the document with a custom root element is also a valid option I guess.

from aexml.

marcuswu0814 avatar marcuswu0814 commented on August 20, 2024

I facing the same issue, through some code trace, AEXMLOptions currently not possible to extend other headers.

As a work around, I create a new class inherit from AEXMLDocument and override the xml computed property like this:

class PlistDocument: AEXMLDocument {
    
    override var xml: String {
        var xml =  "\(options.documentHeader.xmlString)\n"
        let plistDTD = """
        <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">\n
        """
        xml += plistDTD
        xml += root.xml
        return xml
    }
    
}

It work expected. Any better solution for this requirement or if need some enhancement for AEXMLOptions (maybe some refactor with DI), feel free to tell me and I will make a PR when I get free time. 😅

===

P.S.

Maybe somebody would say why not using PropertyListSerialization to make Plist file in my case.

I have no idea how to handle NSNumber and wrong precision of floating number in the black box of PropertyListSerialization. 🤦‍♂️

from aexml.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.