Autor Beitrag
D.Follmann
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 31



BeitragVerfasst: Fr 28.03.08 11:52 
Hallo zusammen,

ich habe eine Frage zu einer XML-Schema-Funktion.
Folgende Funktion hätte ich gerne:

In einem XML-Dokument ( siehe Beispiel) sind verschiedene Elemente vorhanden, die jeweils mehrere Unterelemente enthalten können.
Das Beispieldokument enthält in den "Para"-Elementen in der Gruppe "Paras" Unterelemente mit der Bezeichnung "PTIndex" mit einem int-Wert.
Außerdem enthalten Die "Plaintext"-Elemente in der Gruppe "Plaintexts" ebenfalls ein Element Namens "PTIndex".
Bei der Validierung soll nun überprüft werden, ob zu jedem "Para"-Element das zugehörige "Plaintext"-Element vorhanden ist. ansonsten soll ein Validierungsfehler auftreten.
Sprich: zum 1."Para"-Element im Beispiel (PTIndex=1) ist das zugehörige "Plaintext"-Element vorhanden(PTIndex auch = 1). Zum 2. "Para"-Element (PTIndex = 4) ist jedoch kein passendes "Plaintext"-Element vorhanden => Hier soll ein Fehler auftreten!


======================================
Beispiel:
======================================
ausblenden XML-Daten
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
<?xml version="1.0" encoding="iso-8859-1"?>
<RootElement xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="Schema.xsd">
 <Paras>
   <Para>
     <a/>
     <b/>
     <PTIndex>1</PTIndex>
   </Para>
   <Para>
     <a/>
     <b/>
     <PTIndex>4</PTIndex>
   </Para>
 </Paras>
 <PlainTexts>
  <PlainText>
     <c/>
     <d/>
     <PTIndex>1</PTIndex>
  </PlainText>
  <PlainText>
     <c/>
     <d/>
     <PTIndex>2</PTIndex>
  <PlainText>
 </PlainTexts>
</RootElement>

====================================


Gibt es mit XSD-Schemata eine Möglichkeit dies zu realisieren? Wenn ja, welche?

Vielen Dank im vorraus!

MfG

Dominik
Kha
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3803
Erhaltene Danke: 176

Arch Linux
Python, C, C++ (vim)
BeitragVerfasst: Fr 28.03.08 14:16 
Das dürfte nicht funktionieren, denn das ist alles andere als schönes hierarchisches XML :zwinker: . Mit solch einer relationalen Struktur wird Xsd nichts anfangen könne, das müsste schon so aussehen:
ausblenden XML-Daten
1:
2:
3:
4:
<Item PTIndex="0">
  <Para>...</Para>
  <PlainText>...</PlainText>
</Item>
D.Follmann Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 31



BeitragVerfasst: Fr 28.03.08 15:18 
Doch, das ist hierarschisch!an welcher stelle denn bitte nciht?!?
Habe gerade herausgefunden, dass das mit kex/keyref zu realisieren ist. probiere gerade ein bisschen damit rum. funktioniert auch schon ganz gut...
Kha
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3803
Erhaltene Danke: 176

Arch Linux
Python, C, C++ (vim)
BeitragVerfasst: Sa 29.03.08 00:32 
user profile iconD.Follmann hat folgendes geschrieben:
Doch, das ist hierarschisch!an welcher stelle denn bitte nciht?!?
Naja, mein erster Gedanke beim Durchlesen des XMLs war: "Könnte man direkt in zwei Tabellen umwandeln und in eine relationale DB werfen" ;) . Zum Glück bin anscheinend nicht allein mit der Einschätzung:
Zitat:
I have used [key & keyref] for implementation of what would just be 1:N and 1:1
referential integrity in a relational system and found no difficulty at
that level. I think I lack the standard working methods and "mind set"
that help carry me through design and implementation with relational or
other traditional systems when it comes to using the facilities that
key/keyref offer. Once off the "beaten track" and into more complicated
territory it is easy to get in a muddle. There is a lot of power there,
but ...

In dem Thread finden sich auch ein paar Warnungen vor keyref. Ist aber wirklich interessant, dass es so etwas gibt :gruebel: .