Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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: 28 days ago
JSON representation
Convert a xml file to a C# class and vice versa.
- Host: GitHub
- URL: https://github.com/laurentdardenne/xmlobject
- Owner: LaurentDardenne
- Created: 2016-09-11T21:21:02.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2017-06-17T07:04:19.000Z (over 7 years ago)
- Last Synced: 2024-08-14T07:05:57.841Z (3 months ago)
- Topics: powershell, powershell-modules, wrapper, xml, xsd
- Language: PowerShell
- Size: 24.4 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
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.dllImport-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"
```