Showing posts with label XML. Show all posts
Showing posts with label XML. Show all posts

Monday, August 6, 2007

XML general definition

If you are working with XML, XSD and XSLT don't forget to create and use general definitions in a specific file that you can use in all documents. If you create a XSD with the definitions you want to use.

Example:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.utvecklargodis.com/GeneralDefinitions/1.0" targetNamespace="http://www.utvecklargodis.com/GeneralDefinitions/1.0" elementFormDefault="unqualified" attributeFormDefault="unqualified">
<!-- GUID -->
<xs:simpleType name="GUID">
<xs:annotation>
<xs:documentation>General definition of a GUID</xs:documentation>
</xs:annotation>
<xs:restriction base="xs:string">
<xs:pattern value="[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}"/>
</xs:restriction>
</xs:simpleType>
<!-- /GUID -->
</xs:schema>


Then you use the general definition like this:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://www.utvecklargodis.com/system/2.0" xmlns:ns1="http://www.utvecklargodis.com/system/GeneralDefinitions/1.0" elementFormDefault="unqualified" attributeFormDefault="unqualified">
<xs:import namespace="http://www.utvecklargodis.com/system/GeneralDefinitions/1.0" schemaLocation="./General.xsd"/>
<xs:element name="Objects">
<xs:complexType>
<xs:element name="ObjectID" type="ns1:GUID"/>
</xs:complexType>
</xs:element>
</xs:schema>

Friday, July 6, 2007

Trim function for XSLT

I needed a function for a XSLT that will trim a string. Here it is.

First you got an example of how to use the function.

<Cancel>
<xsl:call-template name="trimString">
<xsl:with-param name="s" select="./CANCEL"/>
</xsl:call-template>
</Cancel>

And here is the trim function.

<!-- Template for trimming strings -->
<!-- Left Trim -->
<xsl:template name="leftTrim">
<xsl:param name="inParam"/>
<xsl:choose>
<xsl:when test="substring($inParam, 1, 1) = ''">
<xsl:value-of select="$inParam"/>
</xsl:when>
<xsl:when test="normalize-space(substring($inParam, 1, 1)) = ''">
<xsl:call-template name="leftTrim">
<xsl:with-param name="inParam" select="substring($inParam, 2)"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$inParam"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

<!-- Right Trim -->
<xsl:template name="rightTrim">
<xsl:param name="inParam"/>
<xsl:choose>
<xsl:when test="substring($inParam, 1, 1) = ''">
<xsl:value-of select="$inParam"/>
</xsl:when>
<xsl:when test="normalize-space(substring($inParam, string-length($inParam))) = ''">
<xsl:call-template name="rightTrim">
<xsl:with-param name="inParam" select="substring($inParam, 1, string-length($inParam) - 1)"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$inParam"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- Trim by using right and left trim -->
<xsl:template name="trimString">
<xsl:param name="inParam"/>
<xsl:call-template name="rightTrim">
<xsl:with-param name="inParam">
<xsl:call-template name="leftTrim">
<xsl:with-param name="inParam" select="$inParam"/>
</xsl:call-template>
</xsl:with-param>
</xsl:call-template>
</xsl:template>

Tuesday, June 26, 2007

Using import and XSD.EXE

I was going to use XSD.exe on a XSD I made. The XSD was importing a XSD with general definitions
.

First when trying to use XSD.exe to generate the C# class it didn't found the imported schema. Then I added the imported XSD to the command in my bat file (that I use instead of writing in the command line every time).

Now it works! The bat file looks like this

"C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\xsd.exe" Object.xsd "./General/General.xsd" /c /l:cs /edb /n:Company.Project.BusinessEntities
pause

Thats all.

Sunday, March 25, 2007

XML Diff

This is an article with sourcecode for an application that compares two XML messages and generates XML DiffGram and shows the XML and the diffs in a HTML document.

Read the article and download the code here.

Saturday, March 24, 2007

XML Notepad 2007

If you working with XML you must download XML Notepad 2007.