I am missing something and I can't figure it out. I am trying to create an XML element and append it into an existing XML document.
<!-- It Should Look Like This -->
<Reminder ID="f6c11f43-c978-492b-bb5e-992eb93a78cd">
<Title><![CDATA[This should be a title]]></Title>
<Message><![CDATA[This should be a message]]></Message>
<When>
This should be something too
</When>
</Reminder>
<!-- It comes out looking like this though -->
<Reminder ID="f6c11f43-c978-492b-bb5e-992eb93a78cd">
<Title><![CDATA[]]></Title>
<Message><![CDATA[]]></Message>
<When>
</When>
</Reminder>
The following code creates the above emptiness
Function New-Reminder($Reminder) {
# Get-MyNotification retus the file as XML
$XMLBase = Get-MyNotification
$ReminderElement = $XMLBase.CreateElement("Reminder")
$WhenElement = $XMLBase.CreateElement("When")
$TitleElement = $XMLBase.CreateElement("Title")
$MessageElement = $XMLBase.CreateElement("Message")
$ReminderElement.SetAttribute("ID", [Guid]::NewGuid())
$TitleCData = $XMLBase.CreateCDataSection($Reminder.Title)
$MessageCData = $XMLBase.CreateCDataSection($Reminder.Message)
$WhenContent = $XMLBase.CreateTextNode($Reminder.When)
$TitleElement.AppendChild($TitleCData)
$MessageElement.AppendChild($MessageCData)
$WhenElement.AppendChild($WhenContent)
$ReminderElement.AppendChild($TitleElement)
$ReminderElement.AppendChild($MessageElement)
$ReminderElement.AppendChild($WhenElement)
$XMLBase.DocumentElement.Reminders.AppendChild($ReminderElement)
$XMLBase.Save("$PSScriptRootMyNotification.xml")
}
A reminder is passed as a hashtable
$Reminder = @ {
"Title" = "I'm a title"
"Message" = "I'm a message"
"When" = "Three years from now"
}
The function is called as such:
New-Reminder $Reminder
Writing information out in the console from the New-Reminder function shows that $Reminder is getting passed successfully. Can anybody see where I am going wrong? Why are my nodes showing up blank in the output?
