Examples needed.
Thanks!
Examples needed.
Thanks!
Just a quick hack:
PS>
"<hash><entry><key>foo</key><value>1</value></entry><entry><key>bar</key><value>2</value></entry></hash>" | out-file hashXML.txt
PS> $hashXML = [xml] (get-content hashXML.txt)
PS> $hashXML.hash.entry | % { $hash = @{} } { $hash += @{$_.key = $_.value} }
PS> $hash
Name Value
---- -----
bar 2
foo 1
--
greetings
dreeschkind
"wangxiaohu" wrote:
> Examples needed.
>
> Thanks!
"wangxiaohu" <wangxiaohu@discussions.microsoft.com> wrote in message
newsAC2BF59-B9C8-404E-AAEC-04FA61428085@microsoft.com...
> Examples needed.
Unless every element name is unique i.e. maxOccurs is never more than 1, I
don't see how this would be helpful? Hashtables perform fast lookups based
off of a unique key, if the key isn't unique then a hashtable is a good fit.
Did you know that if you just convert a string to [xml] you get a full
System.Xml.XmlDocument object? For example:
PS> $xml =
[xml]"<doc><element1>Foo</element1><element1>Bar</element1></doc>"
PS> $xml.doc
element1
--------
{Foo, Bar}
PS> $xml.doc.element1[0]
Foo
PS>$xml.GetElementsByTagName("element1")
#text
-----
Foo
Bar
Or you could use XPath expressions:
PS>$xml.SelectNodes("//element1")
#text
-----
Foo
Bar
--
Keith
"Keith Hill [MVP]" <r_keith_hill@mailhot.moc.nospam> wrote in message
news:%235xu8ia8GHA.2120@TK2MSFTNGP03.phx.gbl...
> "wangxiaohu" <wangxiaohu@discussions.microsoft.com> wrote in message
> newsAC2BF59-B9C8-404E-AAEC-04FA61428085@microsoft.com...
>> Examples needed.
>
> Unless every element name is unique i.e. maxOccurs is never more than 1, I
> don't see how this would be helpful? Hashtables perform fast lookups
> based off of a unique key, if the key isn't unique then a hashtable is a
> good fit.
Doh! That should be "if the key isn't unique then a hashtable is *not* a
good fit".
--
Keith
| Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Sorting a Hash Table before outputting it to html | TimParker | PowerShell | 3 | 03 Jan 2009 |
| How to create a hash table from an array | RickB | PowerShell | 2 | 08 Aug 2008 |
| Adding data to a hash table | NeilOz | PowerShell | 3 | 27 Dec 2007 |
| Passing hash table by reference | Orimslala | PowerShell | 2 | 12 Sep 2007 |
| Variable as hash table issue | Romu | PowerShell | 2 | 22 Jan 2007 |