djc / rnc2rng

RELAX NG Compact to regular syntax conversion library
MIT License
16 stars 13 forks source link

Attributes should have ns="" as namespace #8

Closed ghost closed 7 years ago

ghost commented 7 years ago

While elements inherit the namespace of their parent, attributes do not. See the official tutorial.

This rnc:

default namespace = "https://namespace.com"
MyEl = element elem { attribute utils { text } }

should produce this rng:

<?xml version="1.0" encoding="UTF-8"?>
<grammar xmlns="http://relaxng.org/ns/structure/1.0"
         ns="https://namespace.com">
  <define name="MyEl">
    <element>
      <name ns="https://namespace.com">elem</name>
      <attribute>
        <name ns="">utils</name>
        <text/>
      </attribute>
    </element>
  </define>
</grammar>

and not this:

<?xml version="1.0" encoding="UTF-8"?>
<grammar xmlns="http://relaxng.org/ns/structure/1.0"
         ns="https://namespace.com">
  <define name="MyEl">
    <element>
      <name ns="https://namespace.com">elem</name>
      <attribute>
        <name ns="https://namespace.com">utils</name>
        <text/>
      </attribute>
    </element>
  </define>
</grammar>
djc commented 7 years ago

Can you review c2586be076901b32d16ef9ac8971fa6d38d673d9, please?

If you're happy (and have no other bugs/concerns), I can put out a new release.

ghost commented 7 years ago

Thank'you @djc The patch works perfectly on the snippet I provided, but it seems it doesn't cover this use case I didn't provide yesterday:

default namespace = "https://namespace.com"
MyEl = element elem { attribute * - utils { text } }

(all attributes except "utils")

Produces:

<?xml version="1.0" encoding="UTF-8"?>
<grammar xmlns="http://relaxng.org/ns/structure/1.0"
         ns="https://namespace.com">
  <define name="MyEl">
    <element>
      <name ns="https://namespace.com">elem</name>
      <attribute>
        <anyName>
          <except>
            <name ns="https://namespace.com">utils</name>
          </except>
        </anyName>
        <text/>
      </attribute>
    </element>
  </define>
</grammar>

Should produce:

<?xml version="1.0" encoding="UTF-8"?>
<grammar xmlns="http://relaxng.org/ns/structure/1.0"
         ns="https://namespace.com">
  <define name="MyEl">
    <element>
      <name ns="https://namespace.com">elem</name>
      <attribute>
        <anyName>
          <except>
            <name ns="">utils</name>
          </except>
        </anyName>
        <text/>
      </attribute>
    </element>
  </define>
</grammar>

Should be fine after that, I can't think of other different contexts for attributes.

djc commented 7 years ago

Please try with 2e5c56a and see if that works for you.

ghost commented 7 years ago

Perfect! ✨ You can ship it if you want. Thank'you very much!

djc commented 7 years ago

I've uploaded version 2.4.1 to PyPI.