-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStart-XMLFileProcess.ps1
More file actions
55 lines (50 loc) · 1.86 KB
/
Start-XMLFileProcess.ps1
File metadata and controls
55 lines (50 loc) · 1.86 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
<#
.SYNOPSIS
Process on XML file for the inserting records in respecitve tables.
.DESCRIPTION
A process on XML file for the inserting records in respective tables. However, Read the XML based on the nodes and calling the respective class and split the data into the class methods and assign it to the respective global table objects.
.PARAMETER FileName
Required. XML FilePath
.OUTPUTS
Process the XML file path and stored the data temporarily into the respective global table objects.
.EXAMPLE
Start-XMLFileProcess -FilePath "FullPath/20203001.xml"
#>
function Start-XMLFileProcess() {
[cmdletbinding()]
Param (
[Parameter(Mandatory = $true, Position = 0)]
$FilePath
)
Begin {
$fileDetail = [FileDetailModel]::new($FilePath);
$XmlProcessData = $null;
try {
$XmlProcessData = [xml](Get-Content $FilePath -Encoding:UTF8)
}
catch {
Write-Exception -Message "Package Date: $PackageDate | FilePath: $FilePath";
Write-Exception -ErrorObj $_ -Message "The loading of the xml using UTF7 and ASCII encoding has failed" -Stop $true;
}
}
Process {
try {
$root_data_node = $XmlProcessData."users-data";
$user_node = $root_data_node."user-detail";
if ($Global:Resources.IsDataTable) {
[UsersTable]::ToObjectList($user_node)
}
else {
[UsersTable]::ToQueryList($user_node)
}
}
catch {
Write-Exception -ErrorObj $_ -Message "Throws an Exception in 'Start-XMLFileProcess', FileName: $($fileDetail.FileName)" -Stop $true
}
finally {
Write-LogInfo -Message "Users data read successfully from '$($fileDetail.FileName)' file" -Write $true
}
}
End {
}
}