Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/LaurentDardenne/XMLObject

Convert a xml file to a C# class and vice versa.
https://github.com/LaurentDardenne/XMLObject

powershell powershell-modules wrapper xml xsd

Last synced: 3 months ago
JSON representation

Convert a xml file to a C# class and vice versa.

Awesome Lists containing this project

README

        

# XMLObject
Convert a xml file to a C# class and vice versa.

To install this module :
```Powershell
$PSGalleryPublishUri = 'https://www.myget.org/F/ottomatt/api/v2/package'
$PSGallerySourceUri = 'https://www.myget.org/F/ottomatt/api/v2'

Register-PSRepository -Name OttoMatt -SourceLocation $PSGallerySourceUri -PublishLocation $PSGalleryPublishUri #-InstallationPolicy Trusted
Install-Module XMLObject -Repository OttoMatt
```

Need an xsd file and the dotnet tools xsd.exe.
```powershell
#First step
cd c:\temp
nuget install NuGet.Manifest.Schema
$XsdFile='c:\temp\NuGet.Manifest.Schema.2.0.4\Content\nuspec.2011.8.xsd'
&"C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools\xsd.exe" $XsdFile /Classes /language:CS
#Compile 'nuspec_2011_8.cs' to NugetSchemas.dll
Add-type -path 'C:\temp\nuspec_2011_8.cs' -OutputAssembly 'C:\temp\NugetSchemas.dll' -OutputType Library -ReferencedAssemblies ([Xml].Assembly.Location)

# Second step
$XsdFile='G:\PS\Nuget\nuspec.2011.8.xsd'
$Filename='G:\PS\Nuget\TestNuget.nuspec'
Add-type -path G:\PS\Nuget\NugetSchemas.dll

Import-Module XMLObject

#XML file to a C# class
$Nuspec=ConvertTo-Object -Filename $FileName -SchemaFile $xsdFile -targetNamespace "http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd" -SerializedType 'NugetSchemas.package'
$Nuspec.metadata.title='Test'
#A C# class to a XML file
ConvertTo-XML -Object $Nuspec -Filename $FileName -SerializedType 'NugetSchemas.package' -targetNamespace "http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd"
```