Problem with MSXML6 + namespace + XPath
-
Hi All, I try to use MSXML with xml files which contains namespaces. But I can't figure out how to do! Here is an excerpt of my XML file: <?xml version="1.0" encoding="utf-8"?> <BENCH xmlns:VODPC_VOD="urn:VODPC:VOD:schema:20060809"> <VODPC_VOD:GRAPH state="running" currentFlowID="1" removeOnExit="FALSE"> </VODPC_VOD:GRAPH> </BENCH> When I load the file with MSXML6, no problem. I try to access node BENCH with XPath "/BENCH" : no problem. But when I try to access node VODPC_VOD:GRAPH with XPath "/BENCH/VODPC_VOD:GRAPH", I get an exception, which contain no valuable information: First-chance exception at 0x75ac9617 in XXXXXX.exe: 0xE0000001: 0xe0000001. First-chance exception at 0x75ac9617 in XXXXXX.exe: 0xE0000001: 0xe0000001. First-chance exception at 0x75ac9617 in XXXXXX.exe: 0xE0000001: 0xe0000001. First-chance exception at 0x75ac9617 in XXXXXX.exe: 0xE0000001: 0xe0000001. First-chance exception at 0x75ac9617 in XXXXXX.exe: Microsoft C++ exception: _com_error at memory location 0x0025dac4.. I set these flags before to load: m_pXMLDoc->async = VARIANT_FALSE; m_pXMLDoc->preserveWhiteSpace = VARIANT_TRUE; m_pXMLDoc->validateOnParse = VARIANT_TRUE; m_pXMLDoc->resolveExternals = VARIANT_TRUE; As you can understand, I work in C++. I'm an IT profesionnal since 18 year. My problem is that I do not know what namespace is used in the file, so I don't want to have to tell MSXML6 what namespaces are used IN THE FILE. I guess it's its job, no ? If anybody have an idea ... Thanks a lot Patrice
-
Hi All, I try to use MSXML with xml files which contains namespaces. But I can't figure out how to do! Here is an excerpt of my XML file: <?xml version="1.0" encoding="utf-8"?> <BENCH xmlns:VODPC_VOD="urn:VODPC:VOD:schema:20060809"> <VODPC_VOD:GRAPH state="running" currentFlowID="1" removeOnExit="FALSE"> </VODPC_VOD:GRAPH> </BENCH> When I load the file with MSXML6, no problem. I try to access node BENCH with XPath "/BENCH" : no problem. But when I try to access node VODPC_VOD:GRAPH with XPath "/BENCH/VODPC_VOD:GRAPH", I get an exception, which contain no valuable information: First-chance exception at 0x75ac9617 in XXXXXX.exe: 0xE0000001: 0xe0000001. First-chance exception at 0x75ac9617 in XXXXXX.exe: 0xE0000001: 0xe0000001. First-chance exception at 0x75ac9617 in XXXXXX.exe: 0xE0000001: 0xe0000001. First-chance exception at 0x75ac9617 in XXXXXX.exe: 0xE0000001: 0xe0000001. First-chance exception at 0x75ac9617 in XXXXXX.exe: Microsoft C++ exception: _com_error at memory location 0x0025dac4.. I set these flags before to load: m_pXMLDoc->async = VARIANT_FALSE; m_pXMLDoc->preserveWhiteSpace = VARIANT_TRUE; m_pXMLDoc->validateOnParse = VARIANT_TRUE; m_pXMLDoc->resolveExternals = VARIANT_TRUE; As you can understand, I work in C++. I'm an IT profesionnal since 18 year. My problem is that I do not know what namespace is used in the file, so I don't want to have to tell MSXML6 what namespaces are used IN THE FILE. I guess it's its job, no ? If anybody have an idea ... Thanks a lot Patrice
You have to tell MSXML what namespace prefixes your XPath expressions use. When parsing XML, the parser remmebers the namespace URIs, NOT the prefixes used in the documents. That means that your code has to define the prefix to URI mappings used in your XPaths.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p CodeProject MVP for 2010 - who'd'a thunk it!