Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XML representation omits XML declaration #52

Open
midas opened this issue Jan 3, 2013 · 7 comments
Open

XML representation omits XML declaration #52

midas opened this issue Jan 3, 2013 · 7 comments

Comments

@midas
Copy link

midas commented Jan 3, 2013

After searching representable and roar, I can find no option to include the XML declaration line in the representation. Is there a way to accomplish this or is it an oversight?

@apotonick
Copy link
Member

We left that out by intention! However, I agree with you that this might be handy. So you want the top representer to prepend that to the rendered XML doc?

@midas
Copy link
Author

midas commented Jan 3, 2013

I believe that is what I want. I have not been using roar long enough to completely understand its internals yet, so I would hate to request the wrong thing. This may actually belong in representable.

Seems that when #to_xml is called on a model extended by a representer, the XML declaration line should be there. I myself cannot think of a use case where you may need to turn that off with an option, but there may be some users who desire this?

@QuinnWilton
Copy link

I would also make use of this feature if added. Happy to investigate adding it myself if you can point me in the right direction, but I won't have too much free time over the next week.

@apotonick
Copy link
Member

Maybe we should have the following API?

representer.to_xml(declaration: true)

That would go into Representable::XML#to_xml, @ShaneWilton!

@QuinnWilton
Copy link

That looks easy to use, but how would it handle specifying the version, encoding, and standalone attributes? Of the three, only version is required, so something like this might be more flexible:

representer.to_xml # No XML declaration
representer.to_xml(declaration: nil) # No XML declaration

representer.to_xml(
  declaration: {version: "1.0"}
) # <?xml version="1.0" ?>

representer.to_xml(
  declaration: {
    version: "1.0",
    encoding: "UTF-8",
    standalone: true
  }
) # <?xml version="1.0" encoding="UTF-8" standalone="yes" ?>

representer.to_xml(
  declaration: {
    encoding: "UTF-8",
    standalone: true
  }
) # ArgumentError: Missing required :version argument

@apotonick
Copy link
Member

Up to you, @ShaneWilton! I haven't used XML in ages and will probably never use it, again. I'm actually thinking of introducing representable-xml as a separate, community-managed gem.

@QuinnWilton
Copy link

I haven't used XML in ages and will probably never use it, again.

I'm jealous 😛

Cool, I'll see what I can do about building that. It might be a bit because I'm a little swamped right now. I'll let you know if I have questions about the codebase.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants