How to influence the order in which DOM elements are inserted?
OK, here's an another question. In a specialized editor for an XML file, I can create new elements that are optional in the xml file. When I create a section of the DOM that was not previously in the file.
Can I control where the DomElement is inserted? For example, the XML looks like this before the insert:
]]>
After inserting from the dedicated GUI editor I would like to have:
]]>
But the Intellij seems to have its own prefered location that results in something like:
]]>
Is there any way to influence the order/location of elements?
请先登录再写评论。
Rather strange. In fact they should be inserted to the end of the
collection.Am I right, that you speak about the collection? Then you can
create method like addSubtag2(int index) in your DOM interface, and it will
take the index into account while inserting.
If you're speaking about general insertion order, it's usually done
according to DTD/Schema, if they're present. So you just have to begin your
XML file properly.
"Jan Arend Jansen" <no_mail@jetbrains.com> wrote in message
news:25193202.1160334453809.JavaMail.itn@is.intellij.net...
>
>
>
>
>
>
>
>
Ok, thanks. It maybe the XSD. I'll check.
Unless you're schema is using namespaces - then the order is simply
random... ;)
--
Martin Fuhrer
Fuhrer Engineering AG
http://www.fuhrer.com
After double checking:
1> This is actually not about elements in a collection, but child elements. subtag1, subtag2 and subtag3 are of different complex types
2> The XSD is correctly initialized in the XML and has a different order. The XSD makes heavy use of ComplexType...
I am still confused about this.
Could you please give an example of such a schema? A little one, just the
parent tag and child tag descriptions.
"Jan Arend Jansen" <no_mail@jetbrains.com> wrote in message
news:13575227.1160834874224.JavaMail.itn@is.intellij.net...
>
I am facing the same problem.
I have Setting interface
public interface Setting extends DomElement {
@NotNull
GenericDomValue<String> getEnv();
@NotNull
GenericDomValue<String> getServer();
}
and then I have another interface that extends Setting
public interface OverrideUrl extends DomElement, Setting {
@NotNull
@Required
GenericDomValue<String> getUrl();
}
The Swing components are binded to the DomElement.
The order is
binder.bind(env)
binder.bind(server)
binder.bind(url)
But once the xml/doc is commited, url appears before env and server. I cannot figure out why
If I change the order of binding,
binder.bind(server)
binder.bind(env)
binder.bind(url)
Now the server comes above env.. But url still comes at the top.
Is there any annotation that I can add so that url comes in order?
The xsd is as follows
<xs:complexType name="setting" abstract="true">
<xs:sequence>
<xs:element name="env" type="xs:string" minOccurs="0"/>
<xs:element name="server" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
and
<xs:element name="override-url" substitutionGroup="setting">
<xs:complexType>
<xs:complexContent>
<xs:extension base="setting">
<xs:sequence>
<xs:element name="url" type="xs:string"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:element>
Resolved: Turns out @Required elements will always go to the top. In my case, url was marked @required and rest were not.