-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExport-PropertyToXml.ps1
More file actions
91 lines (80 loc) · 3.61 KB
/
Export-PropertyToXml.ps1
File metadata and controls
91 lines (80 loc) · 3.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
function Export-PropertyToXml {
[CmdletBinding()]
param(
[Parameter(Mandatory = $false)]
[string]$breadcrumbRoot = $(Throw ((Get-ResStr 'PARAM_MANDATORY_MISSED') -f 'breadcrumbRoot', $myInvocation.Mycommand))
,
[Parameter(Mandatory = $false)]
[switch]$noEmptyPropertyTree
,
[Parameter(Mandatory = $false)]
[ValidateScript({ Test-ValidateMapping -strValue $_ -mapping (Get-MappingTablename) })]
[string]$tablename = $(Throw ((Get-ResStr 'PARAM_MANDATORY_MISSED') -f 'tablename', $myInvocation.Mycommand))
,
[Parameter(Mandatory = $false)]
[ValidateScript({ Test-ValidatePathXML -path $_ })]
[string]$path
,
[Parameter(Mandatory = $false)]
[AllowNull()]
[ValidateScript({ Test-ValidateConn -conn $_ })]
$conn
,
[Parameter(Mandatory = $false)]
[ValidateScript({ Test-ValidatePathUDL -path $_ })]
[string]$udl
,
[Parameter(Mandatory = $false)]
[ValidateScript({ Test-ValidateConnStr -connStr $_ })]
[string]$connStr
)
begin {
Write-Verbose -Message ((Get-ResStr 'STARTING_FUNCTION') -f $myInvocation.Mycommand)
Test-ValidateSingle -validParams (Get-SingleConnection) @PSBoundParameters
New-Variable -Name 'myConn' -Scope 'Private' -Value ($null)
New-Variable -Name 'newNode' -Scope 'Private' -Value ($null)
New-Variable -Name 'node' -Scope 'Private' -Value ($null)
New-Variable -Name 'xmlMetadata' -Scope 'Private' -Value ($null)
New-Variable -Name 'xmlPropertyTree' -Scope 'Private' -Value ($null)
New-Variable -Name 'result' -Scope 'Private' -Value ('')
$initialVariables = Get-CurrentVariables -Debug:$DebugPreference
}
process {
$myConn = Get-Conn -conn $conn -udl $udl -connStr $connStr
$tablename = Test-ValidateMapping -strValue $tablename -mapping (Get-MappingTablename)
# XML RAW for Root
[xml]$xml = Get-XmlEulandaRoot
# XML RAW for Metadata
[xml]$xmlMetadata = Get-XmlEulandaMetadata
# XML RAW for PropertyTree
if ($breadcrumbRoot) {
[xml]$xmlPropertyTree = Get-XmlEulandaProperty -breadcrumbRoot $breadcrumbRoot -tablename $tablename -conn $myConn
} else {
[xml]$xmlPropertyTree = "<MERKMALBAUM><$($tablename.ToUpper()) /></MERKMALBAUM>"
}
if ($noEmptyPropertyTree -and
$xmlPropertyTree.Merkmalbaum.ChildNodes.Count -eq 1 -and
$xmlPropertyTree.Merkmalbaum.ChildNodes[0].IsEmpty) {
[xml]$xmlPropertyTree = $null
}
$newNode = $xmlMetadata.SelectSingleNode("//METADATA")
$node = $xml.ImportNode($newNode, $true)
$xml.DocumentElement.AppendChild($node) | Out-Null
if ($xmlPropertyTree) {
$newNode = $xmlPropertyTree.SelectSingleNode("//MERKMALBAUM")
$node = $xml.ImportNode($newNode, $true)
$xml.DocumentElement.AppendChild($node) | Out-Null
}
if ($path) {
Format-Xml -xmlString $xml.OuterXml -pathOut $path
} else {
[string]$result = (Format-Xml -xmlString $xml.OuterXml)
}
}
end {
Get-CurrentVariables -InitialVariables $initialVariables -Debug:$DebugPreference
Return $result
}
# Test: Export-PropertyToXml -breadcrumbRoot '\Shop' -tablename 'Article' -udl 'C:\temp\Eulanda_1 Eulanda.udl' -path "$(Get-DesktopDir)\PROPERTYTREE.xml"
# Test: Export-PropertyToXml -breadcrumbRoot '\Produkte' -tablename 'Address' -udl 'C:\temp\Eulanda_1 Eulanda.udl'
}