Skip to content

Commit

Permalink
Add XML namespace configuration for Tokenizer
Browse files Browse the repository at this point in the history
Adds two additional configuration variables `NamespaceUrl` and
`NamespacePrefix` to specify when a namespace is used in the targeted XML
Keyname.

Resolves openalm#46
  • Loading branch information
incarnate committed Sep 5, 2016
1 parent 205d837 commit deec537
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
12 changes: 11 additions & 1 deletion Utilites/Tokenizer/tokenize-ps3.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,15 @@ try {

$xmlraw = [xml](Get-Content $SourcePath)
ForEach ($key in $keys) {
$node = $xmlraw.SelectSingleNode($key.KeyName)
# Check for a namespaced element
if ($key.NamespaceUrl -And $key.NamespacePrefix) {
$ns = New-Object System.Xml.XmlNamespaceManager($xmlraw.NameTable)
$ns.AddNamespace($key.NamespacePrefix, $key.NamespaceUrl)
$node = $xmlraw.SelectSingleNode($key.KeyName, $ns)
} else {
$node = $xmlraw.SelectSingleNode($key.KeyName)
}

if ($node) {
try {
Write-Host "Updating $($key.Attribute) of $($key.KeyName): $($key.Value)"
Expand All @@ -70,6 +78,8 @@ try {
catch {
Write-Error "Failure while updating $($key.Attribute) of $($key.KeyName): $($key.Value)"
}
} else {
Write-Verbose "'$($key.KeyName)' not found in source"
}
}
$xmlraw.Save($tempFile)
Expand Down
10 changes: 9 additions & 1 deletion Utilites/Tokenizer/tokenize.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,15 @@ if (($SourceIsXml) -and ($Configuration)) {

$xmlraw = [xml](Get-Content $SourcePath)
ForEach ($key in $keys) {
$node = $xmlraw.SelectSingleNode($key.KeyName)
# Check for a namespaced element
if ($key.NamespaceUrl -And $key.NamespacePrefix) {
$ns = New-Object System.Xml.XmlNamespaceManager($xmlraw.NameTable)
$ns.AddNamespace($key.NamespacePrefix, $key.NamespaceUrl)
$node = $xmlraw.SelectSingleNode($key.KeyName, $ns)
} else {
$node = $xmlraw.SelectSingleNode($key.KeyName)
}

if ($node) {
try {
Write-Host "Updating $($key.Attribute) of $($key.KeyName): $($key.Value)"
Expand Down
13 changes: 13 additions & 0 deletions Utilites/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,19 @@ If the **Source filename** uses xml namespaces in some nodes, use a generic XPat
"KeyName": "/*[local-name()='configuration']/*[local-name()='connectionStrings']/*[local-name()='add'][@name='serviceUrl']"
...
```
Or specify the namespace URL and prefix in the config, e.g.

```
...
"ConfigChanges": [
{
"KeyName": "/configuration/ns:nlog/ns:targets/ns:target[@name='email']",
"Attribute": "to",
"value": "logs@test.com",
"NamespaceUrl": "http://www.nlog-project.org/schemas/NLog.xsd",
"NamespacePrefix": "ns"
}
```

#### Parameters
Below is the list of inputs for the task:
Expand Down

0 comments on commit deec537

Please sign in to comment.