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

Allow the creation of namespaces higher in the DOM tree #11

Closed
stevenroose opened this issue Mar 6, 2015 · 4 comments
Closed

Allow the creation of namespaces higher in the DOM tree #11

stevenroose opened this issue Mar 6, 2015 · 4 comments

Comments

@stevenroose
Copy link
Contributor

Consider the following example. When a property value is null, the xsi:nil="true" attribute is added and thus the xsi namespace should be defined. However, the <Property> elements are built inside the XrdProperty class so that it has no access to the <XRD> element. The result is that the xsi namespace is added twice. Preferably, the xsi namespace is only defined in the <XRD> element, not in <Link> elements.

<?xml version="1.0" encoding="UTF-8"?>
<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <Property type="test-prop-null" xsi:nil="true" />
  <Link rel="lrdd" template="https://openid.bar.eu/webfinger.json?q={uri}" type="application/jrd+json" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <Property type="http://webhand.org/rel/origin">openid</Property>
    <Property type="also-null-random-test" xsi:nil="true" />
  </Link>
</XRD>

There are several possible solutions, listed in order of preference:

  1. Add a method to add a namespace to an element that will only be included in the final document when it is actually used. This way, the namespace can be added to the desired element, but can be omitted when it is not required.
  2. Define a method in builder that lets you traverse the ancestors of the current place in the tree. This way, one could go back up in the tree towards the element where one wants the namespace to be defined.
  3. (Only works partially.) When a namespace is added that already is defined in an ancestor, ignore it.
@renggli
Copy link
Owner

renggli commented Mar 12, 2015

The described solution (1) would be tricky to implement, but possible from within the XmlBuilder during the building of the tree. Unfortunately I am quite busy right now, so I don't have the time to look into it. However, free to submit a pull-request.

Alternatively (and if you don't want to modify the library) you could write a visitor over the built XML tree that transforms it into an optimised tree. Implementation wise I think this solution would even be simpler, albeit less efficient as the tree needs to be re-traversed and copied.

@stevenroose
Copy link
Contributor Author

I will try to give it a look this week, time isn't my best friend either.

@stevenroose
Copy link
Contributor Author

I got both 1 and 2 implemented. However, I want to know how you want users to opt-in or opt-out for the enhancements.

I'll make a PR and ask you there.

@renggli
Copy link
Owner

renggli commented Mar 19, 2015

This is fixed with aebf5bd.

@renggli renggli closed this as completed Mar 19, 2015
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