xml schema: differentiate nodes with same name

Hans-Joerg Unger

Usenet Archive
Joined
Apr 10, 2007
Messages
1
Reaction score
0
Hi !

How can I differentiate nodes in an xml-schema which have the same name (see "file"-element in the example) , but different locations and meanings in the xml tree:

How can i differentiate the parsing of the file-element depended to it's parent-node ?

A example xml-fragment:
---
<test>
<hello id="FOO">
<file name="hello.txt" /> <===== file element
</hello>
<goodbye id="FOOBAR">
<file id="123123"> <===== file element
<regex name="go.txt"
match='^(.*)AAA(.*)$' value="\\1BAZ" flags="m" /> <regex name="go.txt" match='^(.*)AAA(.*)$' value="\\1BAZAZ" flags="m" /> </file> </goodbye>
---

A example xml-schema fragment:
---
<xsd:element name="test">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="hello" minOccurs="1" maxOccurs="unbounded"/> <xsd:element ref="goodby" minOccurs="1" maxOccurs="unbounded"/> </xsd:sequence> </xsd:complexType> </xsd:element>

<!-- This element points to a file-subelement -->
<xsd:element name="hello">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="file" minOccurs="1" maxOccurs="unbounded"/> </xsd:sequence> </xsd:complexType> </xsd:element>

<!-- This element belongs to the previous element -->
<xsd:element name="file">
....
</xsd:element>

<!-- This element points to a completly different file-subelement --> <xsd:element name="goodbye"> <xsd:complexType> <xsd:sequence> <xsd:element ref="file" minOccurs="1" maxOccurs="unbounded"/> </xsd:sequence> </xsd:complexType> </xsd:element>

<!-- This element belongs to the previous element -->
<xsd:element name="file"">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="regex" minOccurs="1" maxOccurs="unbounded"/> </xsd:sequence> </xsd:complexType> </xsd:element>
---
 

szomiz

Usenet Archive
Joined
Dec 15, 2004
Messages
11
Reaction score
0
U¿ytkownik "Hans-Joerg Unger said:
Hi !

How can I differentiate nodes in an xml-schema which have the same name (see "file"-element in the example) , but different locations and meanings in the xml tree:

yes

<xsd:element name="test" type="testDef"/>

said:
<xsd:sequence>
<xsd:element name="hello" type="helloDef" minOccurs="1" maxOccurs="unbounded"/> <xsd:element name="goodby" type="goodbyDef" minOccurs="1" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
<!-- This element points to a file-subelement -->
said:
<xsd:sequence>
<xsd:element name="file" type="fileDef1" minOccurs="1" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
said:
<!-- This element belongs to the previous element -->
<xsd:complexType name="fileDef1">
....
said:
<!-- This element points to a completly different file-subelement -->
said:
<xsd:sequence>
<xsd:element name="file" type="fileDef2" minOccurs="1" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
said:
<!-- This element belongs to the previous element -->
said:
<xsd:sequence>
<xsd:element ref="regex" minOccurs="1" maxOccurs="unbounded"/> </xsd:sequence> </xsd:complexType>
<!--/xsd:element-->

sz.
 

Martin Honnen

Usenet Archive
Joined
Apr 8, 2000
Messages
6,174
Reaction score
0
Hans-Joerg Unger said:
How can I differentiate nodes in an xml-schema which have the same name (see "file"-element in the example) , but different locations and meanings in the xml tree:

How can i differentiate the parsing of the file-element depended to it's parent-node ?

One way is to simply inline the element definitions e.g.

<xsd:element name="test">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="hello" minOccurs="1" maxOccurs="unbounded"> <xsd:complexType> <xsd:sequence> <xsd:element name="file" minOccurs="1" maxOccurs="unbounded"> <xsd:complexType> <xsd:attribute name="name" type="xsd:string"/> </xsd:complexType> </xsd:element> </xsd:sequence> </xsd:complexType> </xsd:element> <xsd:element name="goodby" minOccurs="1" maxOccurs="unbounded"> <xsd:complexType> <xsd:sequence> <xsd:element name="file" minOccurs="1" maxOccurs="unbounded"> <xsd:complexType> ... </xsd:complexType> </xsd:sequence> </xsd:complexType> <xsd:element> </xsd:sequence> </xsd:complexType> </xsd:element>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
548,050
Messages
3,104,249
Members
248,133
Latest member
DujonT

Latest Threads

Top