Talking about PowerShell Extended Types (includes a TYPES.XSD)

Jim Truher was kind enough to write up some information on getting the most out of PowerShell’s extended type system by showing you how to create your own custom modifications.  I modified his starting schema just a bit to make it more Visual Studio friendly (added targetNamespace attribute).  Copy the following schema text into a file called something like PowerShellTypeData.xsd and then save that file into the <VS8_INSTALLDIR>\Xml\Schemas diretory.  After that when you create a new XML file and type in the first ‘xmlns=" you will get a drop down list of namespace which should contain the targetNamespace used below.  After that you will get Intellisense support in the XML editor in VS 2005:

<?xml version="1.0" encoding="utf-8" ?>
<xs:schema 
  xmlns:xs="http://www.w3.org/2001/XMLSchema" 
  xmlns:vs="http://schemas.microsoft.com/Visual-Studio-Intellisense
  xmlns:pstd="http://schemas.microsoft.com/PowerShell/TypeData/2007/04"
  targetNamespace="http://schemas.microsoft.com/PowerShell/TypeData/2007/04
  elementFormDefault="qualified
  attributeFormDefault="unqualified
  vs:friendlyname="PowerShell Type Data
  vs:ishtmlschema="false"> 

  <xs:element name="Name" type="xs:string" /> 
  <xs:complexType name="NoteProperty"> 
      <xs:all> 
        <xs:element ref="pstd:Name" /> 
        <xs:element name="Value" type="xs:string" /> 
      </xs:all> 
    </xs:complexType> 
  <xs:complexType name="AliasProperty"> 
      <xs:all> 
        <xs:element ref="pstd:Name" /> 
        <xs:element name="ReferencedMemberName" type="xs:string" /> 
      </xs:all> 
    </xs:complexType> 
  <xs:complexType name="ScriptMethod"> 
      <xs:all> 
        <xs:element ref="pstd:Name" /> 
        <xs:element name="Script" type="xs:string" /> 
      </xs:all> 
    </xs:complexType> 
  <xs:complexType name="ScriptProperty"> 
      <xs:sequence> 
        <xs:element ref="pstd:Name" minOccurs="1" maxOccurs="1" /> 
        <xs:element name="GetScriptBlock" type="xs:string" minOccurs="0" maxOccurs="1" /> 
        <xs:element name="SetScriptBlock" type="xs:string" minOccurs="0" maxOccurs="1" /> 
      </xs:sequence> 
    </xs:complexType> 
  <xs:complexType name="CodeReference"> 
      <xs:all> 
        <xs:element name="TypeName"/> 
        <xs:element name="MethodName"/> 
      </xs:all> 
    </xs:complexType> 
  <xs:complexType name="CodeMethod"> 
      <xs:sequence> 
        <xs:element name="Name" type="xs:string"/> 
        <xs:element name="CodeReference" type="pstd:CodeReference"/> 
      </xs:sequence> 
    </xs:complexType> 
  <xs:complexType name="CodeProperty"> 
      <xs:all> 
        <xs:element name="Name" type="xs:string" /> 
        <xs:element name="GetCodeReference" type="pstd:CodeReference" minOccurs="0" maxOccurs="1" /> 
        <xs:element name="SetCodeReference" type="pstd:CodeReference" minOccurs="0" maxOccurs="1" /> 
      </xs:all> 
    </xs:complexType> 
  <xs:complexType name="PropertySet"> 
    <xs:sequence> 
      <xs:element ref="pstd:Name" /> 
      <xs:element name="ReferencedProperties" /> 
      </xs:sequence> 
    </xs:complexType> 
  <xs:complexType name="Members"> 
    <xs:sequence> 
      <xs:choice maxOccurs="unbounded"> 
      <xs:element name="NoteProperty" type="pstd:NoteProperty" /> 
      <xs:element name="AliasProperty" type="pstd:AliasProperty" /> 
      <xs:element name="ScriptProperty" type="pstd:ScriptProperty" /> 
      <xs:element name="CodeProperty" type="pstd:CodeProperty" /> 
      <xs:element name="ScriptMethod" type="pstd:ScriptMethod" /> 
      <xs:element name="CodeMethod" type="pstd:CodeMethod" /> 
      <xs:element name="MemberSet" type="pstd:MemberSet" /> 
      <xs:element name="PropertySet" type="pstd:PropertySet" /> 
      </xs:choice> 
    </xs:sequence> 
  </xs:complexType> 
  <xs:complexType name="MemberSet"> 
      <xs:all> 
        <xs:element name="Name" type="xs:string"/> 
        <xs:element name="Members" type="pstd:Members" /> 
      </xs:all> 
  </xs:complexType> 
  
  <xs:element name="Types"> 
    <xs:complexType> 
      <xs:sequence> 
        <xs:element name="Type" maxOccurs="unbounded"> 
          <xs:complexType> 
            <xs:sequence> 
              <xs:element name="Name" type="xs:string" /> 
              <xs:element name="Members" type="pstd:Members" /> 
            </xs:sequence> 
          </xs:complexType> 
        </xs:element> 
      </xs:sequence> 
    </xs:complexType> 
  </xs:element>
</xs:schema>

Advertisements
This entry was posted in PowerShell. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s