Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > xml schema: differentiate nodes with same name

Reply
Thread Tools

xml schema: differentiate nodes with same name

 
 
Hans-Joerg Unger
Guest
Posts: n/a
 
      04-10-2007
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>
---
 
Reply With Quote
 
 
 
 
szomiz
Guest
Posts: n/a
 
      04-10-2007
Użytkownik "Hans-Joerg Unger" <(E-Mail Removed)> napisał w wiadomości
news:(E-Mail Removed)...
> 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"/>

<xsd:complexType name="testDef">
> <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>

<!--/xsd:element-->
>
> <!-- This element points to a file-subelement -->

<!--xsd:element name="hello"-->
<xsd:complexType name="helloDef">
> <xsd:sequence>

<xsd:element name="file" type="fileDef1" minOccurs="1"
maxOccurs="unbounded"/>
> </xsd:sequence>
> </xsd:complexType>

<!--/xsd:element-->
>
> <!-- This element belongs to the previous element -->

<xsd:complexType name="fileDef1">
....
</xsd:complexType>
>
> <!-- This element points to a completly different file-subelement -->

<!--xsd:element name="goodbye"-->
<xsd:complexType name="goodbyeDef">
> <xsd:sequence>

<xsd:element name="file" type="fileDef2" minOccurs="1"
maxOccurs="unbounded"/>
> </xsd:sequence>
> </xsd:complexType>

<!--/xsd:element-->
>
> <!-- This element belongs to the previous element -->

<!--xsd:element name="file""-->
<xsd:complexType name="fileDef2">
> <xsd:sequence>
> <xsd:element ref="regex" minOccurs="1" maxOccurs="unbounded"/>
> </xsd:sequence>
> </xsd:complexType>

<!--/xsd:element-->

sz.


 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      04-10-2007
Hans-Joerg Unger wrote:

> 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>
--

Martin Honnen
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Nodes with the same name in one XML doc engwar XML 2 11-05-2007 09:48 PM
Dataset Question - Odd results with single xml nodes vs multiple nodes th3dude ASP .Net 0 01-03-2007 03:24 PM
Selecting nodes ith the same attribute name value DiTieM XML 1 02-09-2006 12:52 PM
Text nodes and element nodes query asd Java 3 05-23-2005 10:01 AM
Reality check: Is it sensible to link XML nodes to other XML nodes in the same file? gavnosis XML 0 08-02-2003 08:22 AM



Advertisments