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

to_xml: How to Add a Namespace to the Root Element Only #223

Open
sshaw opened this issue Jul 17, 2023 · 2 comments
Open

to_xml: How to Add a Namespace to the Root Element Only #223

sshaw opened this issue Jul 17, 2023 · 2 comments

Comments

@sshaw
Copy link

sshaw commented Jul 17, 2023

In most cases the namespace only applies to the root element but outputting this sort of XML does not seem possible. For example, given this schema one must output the following:

<ns1:Transmission xmlns:ns1="https://ldex.limra.com/xsd/1.0/LDExBEM">
  <TransmissionGUID>1234106c-d731-466a-8235-3377985285yy</TransmissionGUID>
  <!-- ... -->
</ns1:Transmission>

Now How to achieve this? The namespace method is used "if a node and all its children are all namespaced elements".

The tag method does not accept a namespace argument like element method does. Specifying:

element :transmission_guid, String, :tag => "TransmissionGUID", :namespace => nil

or :namespace => false does not prevent the namespace provided to namespace from being output.

Does not seem possible to output a namespace only on the root element.

@yvesll
Copy link

yvesll commented Jul 19, 2023

Similar scenario in #217, if you use MRI ruby, you can just define a tag with namespace like:

tag 'ns1:Transmission'

@sshaw
Copy link
Author

sshaw commented Jul 21, 2023

Thanks @yvesll but that is just an accident and will be fixed soon so not safe to use long-term.

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

2 participants