XSD to XML Tool

Verstehen wir zufällig etwas anderes unter XSD?

Eine XML Schema Definition (XSD) wird bereits im XML-Format angegeben und dient dazu die Struktur von XML-Dateien zu definieren, die diese Datei einbinden.
 
Bsp.-Abschnitt von der .xsd-File:

XML:
	<xs:complexType name="FXParticleDrawGpu">
		<xs:complexContent>
			<xs:extension base="FXParticleDrawBase">
				<xs:attribute name="Shader" type="AssetId" default="GPUParticle.fx" />
				<xs:attribute name="FramesPerRow" type="SageInt" default="1" />
				<xs:attribute name="TotalFrames" type="SageInt" default="1" />
				<xs:attribute name="DetailTexture" type="TextureRef" />
				<xs:attribute name="SpeedMultiplier" type="SageReal" default="1.0" />
				<xs:attribute name="GeometryType" type="FXParticleSystem_GeometryType" default="SIMPLE_QUAD" />
				<xs:attribute name="SortParticles" type="SageBool" default="false" />
			</xs:extension>
		</xs:complexContent>
	</xs:complexType>

Ich möchte aber, dass es danach (nach der Umwandlung zu .xml) so aussieht:

XML:
	<Asset
		id="FXParticleDrawGpu">
		<EntryInheritance
			id="base"
			AssetType="FXParticleDrawBase" />
		<Entry
			id="Shader"
			AssetType="String"
			IsAttribute="true"
			Default="GPUParticle.fx" />
		<Entry
			id="FramesPerRow"
			AssetType="SageInt"
			IsAttribute="true"
			Default="1" />
		<Entry
			id="TotalFrames"
			AssetType="SageInt"
			IsAttribute="true"
			Default="1" />
		<EntryReference
			id="DetailTexture"
			AssetType="Texture"
			IsAttribute="true" />
		<Entry
			id="SpeedMultiplier"
			AssetType="SageReal"
			IsAttribute="true"
			Default="1.0" />
		<Entry
			id="GeometryType"
			AssetType="FXParticleSystem_GeometryType"
			IsAttribute="true"
			Default="SIMPLE_QUAD" />
		<Entry
			id="SortParticles"
			AssetType="SageBool"
			IsAttribute="true"
			Default="false" />
	</Asset>

Ein vernünftiges Tool habe ich bisher dafür noch nicht gefunden.
 
Wie gesagt, eine XSD-Datei ist auch eine XML-Datei. Aber ich verstehe, du möchtest es anders darstellen. Um bei XSD und XML zu bleiben würde ich dir zur XSL Transformation (XSLT) raten, da dies gerade dazu gedacht ist XML-Dateien zu transformieren.

XML:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/complexType">
  <Asset id="<xsl:value-of select="@name" />">
  <EntryInheritance
    id="base"
    AssetType="<xsl:value-of select="complexContent/extension/@base" />"
    />
  <xsl:for-each select="complexContent/extension/*">
    <xsl:choose>
      <xsl:when test="ends-with(@type, 'Ref')">
        <EntryReference
          id="<xsl:value-of select="@name" />"
          AssetType="<xsl:value-of select="substring(@type, 1, string-length(@type) - 3)" />"
          IsAttribute="true"/>
      </xsl:when>
      <xsl:when test="ends-with(@type, 'Id')">
        <Entry
          id="<xsl:value-of select="@name" />"
          AssetType="String"
          IsAttribute="true"
          Default="<xsl:value-of select="@default" />" />
      </xsl:when>
      <xsl:otherwise>
        <Entry
          id="<xsl:value-of select="@name" />"
          AssetType="<xsl:value-of select="@name" />"
          IsAttribute="true"
          Default="<xsl:value-of select="@default" />" />
      </xsl:otherwise>
    </xsl:choose>
  </xsl:for-each>
  </Asset>
</xsl:template>

</xsl:stylesheet>

Ich habe es zwar nicht getestet, aber dies sollte dir als Startpunkt helfen.
 
Back
Top Bottom