Skip to content

Instantly share code, notes, and snippets.

@quonic
Last active November 22, 2017 20:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save quonic/33e1fe707fc7a592a20321bd6fe51e24 to your computer and use it in GitHub Desktop.
Save quonic/33e1fe707fc7a592a20321bd6fe51e24 to your computer and use it in GitHub Desktop.
"This:"
"<queryxml version='1.0'><entity>Ticket</entity><query><field>TicketNumber<expression op='Equals'>135481</expression></field></query></queryxml>"
"should equal this:"
$doc = new-object System.Xml.XmlDocument
$root = $doc.CreateElement("queryxml")
$root.SetAttribute("version","1.0")
$entity = $doc.CreateElement("entity")
$entity.InnerText = "Ticket"
$query = $doc.CreateElement("query")
$field = $doc.CreateElement("field")
$field.InnerText = "TicketNumber"
$expression = $doc.CreateElement("expression")
$expression.SetAttribute("op","Equals")
$expression.InnerText = "135481"
[void]$field.AppendChild($expression)
[void]$query.AppendChild($field)
[void]$root.AppendChild($entity)
[void]$root.AppendChild($query)
[void]$doc.AppendChild($root)
$doc.OuterXml
@quonic
Copy link
Author

quonic commented Nov 22, 2017

This is a much easier way to logically build an xml file in Powershell. Build from the bottom up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment