February 2019
Intermediate to advanced
626 pages
15h 51m
English
LINQ to XML handles the specification of namespaces by adding an XNamespace object to an XName object, for example:
PS> [XNameSpace]'http://example/cars' + [XName]'engine' LocalName Namespace NamespaceName --------- --------- ------------- engine http://example/cars http://example/cars
As XNamespace expects to have an XName added to it, casting to that type can be skipped, simplifying the expression:
[XNamespace]'http://example/cars' + 'engine'
A query for an element in a specific namespace will use the following format:
using namespace System.Xml.Linq [XDocument]$xDocument = @" <?xml version="1.0"?> <cars xmlns:c="http://example/cars"> <car type="Saloon"> <c:colour>Green</c:colour> <c:doors>4</c:doors> <c:transmission>Automatic</c:transmission> ...
Read now
Unlock full access