<?xml version="1.0" encoding="utf-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
<title>Das GEO-Forum - XML/XSD Sich gegenseitig ausschließende Attribute definieren</title>
<link>http://forum.diegeodaeten.de/</link>
<description>DieGeodaeten.de ist ein geodätisches Portal, welches von Vermessungsingenieuren der HS Neubrandenburg ins Leben gerufen wurde. Neben Neuigkeiten aus den Bereichen Geodäsie und Geoinformatik werden Buchempfehlungen oder Downloads angeboten.</description>
<language>de</language>
<item>
<title>XML/XSD Sich gegenseitig ausschließende Attribute definieren (Antwort)</title>
<content:encoded><![CDATA[<p>Hallo,</p>
<blockquote><p>Die Transformationen brauchst Du ja nur bei Darstellung im Web </p>
</blockquote><p>
Wie kommst Du darauf? Das ist mMn. nicht korrekt bzw. nur ein beschränkter Einsatzbereich. Eine Transformations ist auch nötig, um vom XML zu XML zu konvertieren (mit unterschiedlichen Schemadateien) oder um von XML zu ASCII zu kommen.</p>
<blockquote><p>Ich habe sehr gute Erfahrung gemacht mit dem XML-Parser ...</p>
</blockquote><p>
Ich benötige keinen Parser (im Moment) sondern habe ein Problem bei der Definition des Schemas für meine Daten. Erst wenn das Schema stimmig ist, werde ich mich an einen Parser versuchen. Java bietet ja JDOM und JAXB an. Die Werkzeuge sind sind also nicht das Problem...</p>
<p>Micha</p>
]]></content:encoded>
<link>http://forum.diegeodaeten.de/index.php?id=3485</link>
<guid>http://forum.diegeodaeten.de/index.php?id=3485</guid>
<pubDate>Wed, 24 Aug 2011 16:26:29 +0000</pubDate>
<category>Informationstechnik</category><dc:creator>MichaeL</dc:creator>
</item>
<item>
<title>XML/XSD Sich gegenseitig ausschließende Attribute definieren (Antwort)</title>
<content:encoded><![CDATA[<p>Du bist offensichtlich sehr mit OpenSource beschäftigt <img src="http://forum.diegeodaeten.de/images/smilies/wink.gif" alt=";)" title="zwinker" /> .. Die Transformationen brauchst Du ja nur bei Darstellung im Web <br />
Ich habe sehr gute Erfahrung gemacht mit dem XML-Parser von http://www.nsoftware.com für Closed Source-Geschichten <img src="http://forum.diegeodaeten.de/images/smilies/wink.gif" alt=";)" title="zwinker" /></p>
]]></content:encoded>
<link>http://forum.diegeodaeten.de/index.php?id=3484</link>
<guid>http://forum.diegeodaeten.de/index.php?id=3484</guid>
<pubDate>Wed, 24 Aug 2011 16:11:52 +0000</pubDate>
<category>Informationstechnik</category><dc:creator>GeoMark</dc:creator>
</item>
<item>
<title>XML/XSD Sich gegenseitig ausschließende Attribute definieren</title>
<content:encoded><![CDATA[<p>Hallo,</p>
<p>ich befasse mich gerade ein wenig mit XML. So langsam aber sicher scheint das ja auch für den gemeinen Vermesser mal nötig zu werden. </p>
<p>Konkret geht es um das Erstellen einer Schemadatei (XSD). Ich möchte erreichen, dass sich innerhalb eines Elements zwei Attribute gegenseitig ausschließen - also nicht den selben Wert zugewiesen bekommen. Ein einfaches Beispiel soll das mal beschreiben.</p>
<pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;orte<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ort</span> <span style="color: #000066;">pid</span>=<span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Berlin&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ort</span> <span style="color: #000066;">pid</span>=<span style="color: #ff0000;">&quot;2&quot;</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Hamburg&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ort</span> <span style="color: #000066;">pid</span>=<span style="color: #ff0000;">&quot;3&quot;</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;München&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/orte<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;reise<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;reiseweg</span> <span style="color: #000066;">from</span>=<span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #000066;">to</span>=<span style="color: #ff0000;">&quot;2&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;reiseweg</span> <span style="color: #000066;">from</span>=<span style="color: #ff0000;">&quot;2&quot;</span> <span style="color: #000066;">to</span>=<span style="color: #ff0000;">&quot;3&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;reiseweg</span> <span style="color: #000066;">from</span>=<span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #000066;">to</span>=<span style="color: #ff0000;">&quot;3&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;reiseweg</span> <span style="color: #000066;">from</span>=<span style="color: #ff0000;">&quot;2&quot;</span> <span style="color: #000066;">to</span>=<span style="color: #ff0000;">&quot;2&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span> <span style="color: #808080; font-style: italic;">&lt;!-- dieses soll unterbunden werden --&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/reise<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre><p>Zum Beschreiben einer Route gibt es Orte mit einer eindeutigen ID (key). Diese Schlüssel können innerhalb von <code>from</code> und <code>to</code> beim Element <code>reiseweg</code> eingetragen werden. Dies funktioniert soweit auch ganz gut, da ich hier mit key und keyref arbeiten kann. Meine bisherige XSD sieht somit wie folgt aus:</p>
<pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsd:key</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;keyPid&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsd:selector</span> <span style="color: #000066;">xpath</span>=<span style="color: #ff0000;">&quot;.//ort&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsd:field</span> <span style="color: #000066;">xpath</span>=<span style="color: #ff0000;">&quot;@pid&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsd:key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsd:keyref</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;keyrefPidTo&quot;</span> <span style="color: #000066;">refer</span>=<span style="color: #ff0000;">&quot;oa:keyPid&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsd:selector</span> <span style="color: #000066;">xpath</span>=<span style="color: #ff0000;">&quot;.//reiseweg&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsd:field</span> <span style="color: #000066;">xpath</span>=<span style="color: #ff0000;">&quot;@to&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsd:keyref<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsd:keyref</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;keyrefPidFrom&quot;</span> <span style="color: #000066;">refer</span>=<span style="color: #ff0000;">&quot;oa:keyPid&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsd:selector</span> <span style="color: #000066;">xpath</span>=<span style="color: #ff0000;">&quot;.//reiseweg&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsd:field</span> <span style="color: #000066;">xpath</span>=<span style="color: #ff0000;">&quot;@from&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsd:keyref<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre><p>Was ich damit jedoch nicht erreiche ist, dass ich Einträge wie bspw.: <code>&lt;reiseweg from=&quot;2&quot; to=&quot;2&quot; /&gt;</code>, bei denen <code>from = to</code> ist, unterbinde. Gibt es eine Möglichkeit, so etwas innerhalb des Schemas festzulegen?</p>
<p>Bisher eingefallen ist mir der theoretische Umweg über eine Transformation. Innerhalb der XSLT könnte ich letztlich abfragen, ob <code>from != to</code> ist und nur diese Elemente berücksichtigen. Das könnte also so aussehen:</p>
<pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:template</span> <span style="color: #000066;">match</span>=<span style="color: #ff0000;">&quot;reiseweg&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:if</span> <span style="color: #000066;">test</span>=<span style="color: #ff0000;">&quot;./@from != ./@to&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:copy<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:apply-templates</span> <span style="color: #000066;">select</span>=<span style="color: #ff0000;">&quot;@*|*|text()&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:copy<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:if<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:template<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre><p>Grundsätzlich wäre mir jedoch eine Lösung ohne XSLT lieber, da ich bei der Transformation aufpassen muss, dass nicht an anderer Stelle durch diese Reduktion invalides XML erzeugt wird.</p>
<p>Über ein paar Anregungen freue ich mich!</p>
<p>Gruß Micha</p>
]]></content:encoded>
<link>http://forum.diegeodaeten.de/index.php?id=3253</link>
<guid>http://forum.diegeodaeten.de/index.php?id=3253</guid>
<pubDate>Mon, 21 Feb 2011 18:20:18 +0000</pubDate>
<category>Informationstechnik</category><dc:creator>MichaeL</dc:creator>
</item>
</channel>
</rss>
