Skip to content

Instantly share code, notes, and snippets.

@jonpryor
Created June 28, 2011 13:43
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 jonpryor/1051157 to your computer and use it in GitHub Desktop.
Save jonpryor/1051157 to your computer and use it in GitHub Desktop.
csharp> var x = "<response xmlns='http://example.org/'><video>Hi!</video></response>";
csharp> var xs = new StringReader(x);
csharp> var d = new XmlDocument();
csharp> d.Load(xs);
csharp> foreach (XmlNode n in d.DocumentElement.SelectNodes("video")) Console.WriteLine(n.Name);
# Note: no output
csharp> var mgr = new XmlNamespaceManager (d.NameTable);
csharp> mgr.AddNamespace("lol", "http://example.org/");
csharp> foreach (XmlNode n in d.DocumentElement.SelectNodes("lol:video", mgr)) Console.WriteLine(n.Name);
video
# Note: you need to pass the XmlNamespaceManager to SelectNodes().
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment