Example of XML namespace handling
Answered
Hello ! I'm struggling with xml dom description when it come to namespacing.
I habe a basic dom description implemented (With tags and subtags only).
I need to access values in specific namespaces, for example :
<resource xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://ofbiz.apache.org/dtds/ofbiz-properties.xsd">
<property key="Accounting">
<value xml:lang="ar">المحاسبة</value>
<value xml:lang="cs">Účetnictví</value>
<value xml:lang="de">Buchhaltung</value>
<value xml:lang="zh-CN">会计</value>
<value xml:lang="zh-TW">會計</value>
</property>
</resource>
In the above case, i'd like to be able to get the value inside the tag
<value xml:lang="zh-CN">会计</value>
How would i acces :
- the lang attribute namespace
- the value inside it ?
For now this is what i have :
import com.intellij.util.xml.*
import com.intellij.util.xmlb.annotations.Attribute
interface UiLabelFile extends DomElement {
@SubTagList("property")
List<Property> getProperties()
interface Property extends DomElement {
@NameValue
@Attribute("key")
GenericAttributeValue<String> getKey()
@SubTagList("value")
List<PropertyValue> getPropertyValues()
}
interface PropertyValue extends DomElement {
}
}
I looked for examples and topics and found this one, but i don't seem to be able to find the class online or in github repo org.jetbrains.android.dom.AndroidAttributeValue
Thanks !
Please sign in to leave a comment.
See https://github.com/JetBrains/android/blob/master/android/src/org/jetbrains/android/dom/DomTypes.kt
Hi Yann, and thanks for your answer, although it's still not clear to me.
From what i understood, i have to register namespace policy with a key, but for android for axample, it links to an external resource, and i don't have such a link.
I tried the following,n but i didn't work (obviously).
The Property.getPropertyValues() returns and empty array
And my second point would be the question of the value inside the <value/> tag. How do i access it ?
The way i do it doesn't work either.
Hooray !! Managed to get the value of lang attr. Thanks for your help.
Now i'm still stucked with the value inside the tag, how would one get the value of the tag in such a case ? @Text doesn't work
What should `@Text` be? Use https://plugins.jetbrains.com/docs/intellij/xml-dom-api.html#tag-content
Hi yann, found it about an hour before your answer, and didn't get time to answer after this.
I'm all set now, thank you for your help and patience