Handling namespaced attribute in Code Inspections

Answered

I'm running code inspection for an XML file and need to handle a namespaced attribute.

For this tag:

<tag1 ns:attr="value" />

I currently have

interface Tag1 : DomElement {
@get:Required
@get:Attribute("ns:attr")
val attr: GenericAttributeValue<String?>
}

But it errors out because com.intellij.util.xml.Attribute doesn't handle namespaces.

What's the right way to create the appropriate interface for Tag1?

3 comments
Comment actions Permalink

Specify com.intellij.util.xml.Namespace to specify namespace for given tag/attribute in DOM model.

0
Comment actions Permalink

Hi Yann, could you provide an example of what that would look like for an attribute?

I've tried 

interface Tag1 : DomElement {
@get:Required
@get:Namespace("ns")
@get:Attribute("attr")
val attr: GenericAttributeValue<String?>
}

as well as a few other variants but I couldn't get it to work.

I've scoured code examples, but I've only seen Namespace used with tags and not with Attributes. Any additional guidance you can provide would be really helpful.

0
Comment actions Permalink

Yann Cebron Do you have any examples of com.intellij.util.xml.Namespace working on Attributes and not tags?

0

Please sign in to leave a comment.