perfectxml.com
 Basic Search  Advanced Search   
Topics Resources Free Library Software XML News About Us
home » focus » msxml » ask a question » past questions & answers Friday, 12 October 2007
 
NEWS
MSXML 4.0 SP2 now available!

 
MSXML
Basics
DOM
SAX
XPath
XSLT
Schemas
SOM
HTTP Access
.NET
Data Islands
Ask a Question
   Past Q&As
C++ Samples
DLL/Version Info
Reference Guide
Books
KB Articles
   HOW TO
   SAMPLE
   INFO
   BUG/PRB
   FIX
   Misc.
MSXML Tips
   August 2002
   September 2002
MSXML Tools

Microsoft XML Core Services


Go back to list of previously asked questions and answers

Question: Is there a way to find out the namespaces prefixes used in the document? For instance, I have the following XML document:
<?xml version="1.0"?>
<group xmlns:p='urn:example-org:People' xmlns:ci="IjustWannaFindThisPrefix">
  <p:date>1970-09-30</p:date>
  <p:degrees>67.5</p:degrees>
</group>
I just want to find out the namespaces prefixes used (p and ci in the above sample XML).
Asked By: Larry
Viewed: 1838
Answer: The only way we know to find out the namespaces prefixes used in the document (such as p and ci in your sample XML document), without using IMXNamespaceManager, is to iterate over the attributes collection, as shown in the following VB sample:

Save your XML document as c:\1.xml
<?xml version="1.0"?>
<group xmlns:p='urn:example-org:People' xmlns:ci="IjustWannaFindThisPrefix">
  <p:date>1970-09-30</p:date>
  <p:degrees>67.5</p:degrees>
</group>

Add reference to MSXML 4.0 in a VB (Visual Basic) app and write the following code:
Dim objXML As New MSXML2.DOMDocument40

objXML.async = False
objXML.validateOnParse = False

If objXML.Load("c:\1.xml") Then
    For Each nsAttr In objXML.documentElement.Attributes
        MsgBox nsAttr.baseName
    Next
Else
    'Failed to load the document, do error handling
End If


Go back to list of previously asked questions and answers
  Contact Us |  | Site Guide | About PerfectXML | Advertise ©2004 perfectxml.com. All rights reserved. | Privacy