---
title: "XML, Namespace, XPath ..."
type: "forum-thread"
url: "https://www.webforum.nu/amne/dotnet/175437-xml-namespace-xpath"
topic: ".NET"
topic_url: "https://www.webforum.nu/amne/dotnet"
author: "l-boy"
published: "2008-11-21T09:50:15.000Z"
updated: "2008-11-21T10:40:18.000Z"
replies: 1
views: 369
page: 1
pages: 1
language: "sv-SE"
site: "webForum — webforum.nu"
rights: "Upphovsrätten till varje inlägg tillhör dess författare."
attribution: "Citera som: webForum, https://www.webforum.nu/amne/dotnet/175437-xml-namespace-xpath"
---

# XML, Namespace, XPath ...

## #1 — l-boy, 2008-11-21T09:50Z

Har en xml som ser ut såhär:

```

<?xml version="1.0" encoding="utf-8"?>
<MicroGroupItemListControl xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://webservices.masterpiece.dk/webservices/SiteCommerce">
  <OrderByType>Name</OrderByType>
  <SubgroupName>Aktiviteter</SubgroupName>
  <SubjectName>Bål / Grillning</SubjectName>
  <MicroGroupItems>
    <MicroGroupInfo>
      <MicroGroupName>Bål  Och Grill</MicroGroupName>
      <CommerceProductItems>
        <CommerceProductItem>
          <CommerceItemGuid>330303</CommerceItemGuid>
        </CommerceProductItem>
        <CommerceProductItem>
          <CommerceItemGuid>330304</CommerceItemGuid>
        </CommerceProductItem>
...
```

Försöker med hjälp av xpath att plocka ut t.ex alla noder under CommerceProductItems men det vill sig inte. Har läst mig till att det har med namespaces att göra men kan ändå inte få till det.

Har kommit så här långt men nu vet jag inte hur jag skall bära mig åt...

```

XmlDocument d = new XmlDocument();

d.Load(xmlurl);

XmlNamespaceManager nsm = new XmlNamespaceManager(d.NameTable);
nsm.AddNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
nsm.AddNamespace("xsd", "http://www.w3.org/2001/XMLSchema");

XmlNodeList nodelist = d.SelectNodes("???");

foreach (XmlNode node in nodelist)

...
```

Permalänk: https://www.webforum.nu/p/175437

## #2 — l-boy, 2008-11-21T10:40Z

Löste sig. Funkar fint med t.ex:

```

nsm.AddNamespace("ns", "http://webservices.masterpiece.dk/webservices/SiteCommerce");

XmlNodeList nodelist = d.SelectNodes("/ns:MicroGroupItemListControl/ns:MicroGroupItems/ns:MicroGroupInfo/ns:CommerceProductItems/ns:CommerceProductItem[ns:CommerceItemGuid=330303, nsm);
```

Permalänk: https://www.webforum.nu/p/2156964

---

Tråden på webben: https://www.webforum.nu/amne/dotnet/175437-xml-namespace-xpath
