code_junkie

XPATHS and Default Namespaces

Nov 10th, 2011
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. XmlDocument doc = new XmlDocument();
  2. doc.LoadXml(xmlWithBogusNamespace);
  3. XmlNamespaceManager nSpace = new XmlNamespaceManager(doc.NameTable);
  4. nSpace.AddNamespace("myNs", "http://theirUri");
  5.  
  6. XmlNodeList nodes = doc.SelectNodes("//myNs:NodesIWant",nSpace);
  7. //etc
  8.  
  9. <foo xmlns='urn:foo'>
  10.  
  11. <bar>
  12.  
  13. <asdf/>
  14.  
  15. </bar>
  16.  
  17. </foo>
  18.  
  19. //*[local-name()='bar']
  20.  
  21. //bar
  22.  
  23. <xsl:stylesheet
  24. xmlns:fb="uri"
  25. xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  26.  
  27. <xsl:template match="fb:foo/bar">
  28. <!-- do stuff here -->
  29. </xsl:template>
  30. </xsl:stylsheet>
Add Comment
Please, Sign In to add comment