Mobinex
asked on
How to load/save xml attributes with xml:lang with DOM in C++?
Hi Experts,
I have xml file as below:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<employer id="100">
<name xml:lang="en">Tri, Tran</name>
<description xml:lang="en">Deve</descri ption>
<name xml:lang="cn"> ø À÷</name>
<description xml:lang="cn">b‚s</description>
<name xml:lang="vn"> Tr§n Hïu Trí</name>
<description xml:lang="vn">MÙt cái ·c t£ Ã kiÃm tra</description>
<age>25</age>
</employer>
I used msxml to load and parser xml document.
My question is how to work with xml:lang with msxml (DOM) in C++, it means how I can get the attributes base on language or location,
If now, I just want to get english text (xml:lang="en") then how to do?.
Pls help me for this soon.
Thank in advance!
I have xml file as below:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<employer id="100">
<name xml:lang="en">Tri, Tran</name>
<description xml:lang="en">Deve</descri
<name xml:lang="cn"> ø À÷</name>
<description xml:lang="cn">b‚s</description>
<name xml:lang="vn"> Tr§n Hïu Trí</name>
<description xml:lang="vn">MÙt cái ·c t£ Ã kiÃm tra</description>
<age>25</age>
</employer>
I used msxml to load and parser xml document.
My question is how to work with xml:lang with msxml (DOM) in C++, it means how I can get the attributes base on language or location,
If now, I just want to get english text (xml:lang="en") then how to do?.
Pls help me for this soon.
Thank in advance!
ASKER
Can you explain about:
pXMLDoc->setProperty("Sele ctionLangu age", "XPath");
What SelectionLanguage and XPath properties? these properties defined by MSXML engine?
pXMLDoc->setProperty("Sele
What SelectionLanguage and XPath properties? these properties defined by MSXML engine?
Yes.
SelectionLanguage is a private property of MSXML, not part of XML standard.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
oh, Hi OnegaZhang
I have more question about setPropeties and MSXML library.
I see setPropeties is supported for msxml4.dll and IXMLDOMDocument2Ptr
I am using msxml.dll and IXMLDOMDocumentPtr, using namespace MSXML not MSXML2.
So how I can know what msxml is supported by system? I mean how we sure our parser xml can work on any system that has msxml.dll or msxml3.dll or msxml.4,....
How to load xml:lang with IXMLDOMDocumentPtr?
My loading function is:
hRes = document.CreateInstance(L" Msxml2.DOM Document.4 .0");
if (FAILED(hRes))
{
hRes = document.CreateInstance(L" Msxml2.DOM Document.3 .0");
if (FAILED(hRes))
{
hRes = document.CreateInstance(L" Msxml2.DOM Document.2 .6");
if (FAILED(hRes))
{
hRes = document.CreateInstance(L" Msxml2.DOM Document") ;
if (FAILED(hRes))
{
hRes = document.CreateInstance(L" Msxml.DOMD ocument");
if(FAILED(hRes)){
throw DOMException(L"Can not get Instance of Msxml DOMDocument");
}
}
}
}
}
so, it suported MSXML2?
Pls help me again to clear what need to do and how to sure our parser can work on any msxml library that is in any system.
Thank again!
I have more question about setPropeties and MSXML library.
I see setPropeties is supported for msxml4.dll and IXMLDOMDocument2Ptr
I am using msxml.dll and IXMLDOMDocumentPtr, using namespace MSXML not MSXML2.
So how I can know what msxml is supported by system? I mean how we sure our parser xml can work on any system that has msxml.dll or msxml3.dll or msxml.4,....
How to load xml:lang with IXMLDOMDocumentPtr?
My loading function is:
hRes = document.CreateInstance(L"
if (FAILED(hRes))
{
hRes = document.CreateInstance(L"
if (FAILED(hRes))
{
hRes = document.CreateInstance(L"
if (FAILED(hRes))
{
hRes = document.CreateInstance(L"
if (FAILED(hRes))
{
hRes = document.CreateInstance(L"
if(FAILED(hRes)){
throw DOMException(L"Can not get Instance of Msxml DOMDocument");
}
}
}
}
}
so, it suported MSXML2?
Pls help me again to clear what need to do and how to sure our parser can work on any msxml library that is in any system.
Thank again!
#include "stdafx.h"
#include <TCHAR.H>
#include <stdio.h>
#include <time.h>
#import "msxml4.dll"
using namespace MSXML2;
inline void EVAL_HR( HRESULT _hr )
{ if FAILED(_hr) throw(_hr); }
void printMSXMLError(const IXMLDOMDocument2Ptr& pXMLDoc)
{
try
{
IXMLDOMParseErrorPtr pError = NULL;
EVAL_HR(pXMLDoc->get_parse
_ftprintf(stderr, pError->reason);
}
catch(...)
{//Exception handling
}
}
int main(int argc, char* argv[])
{
try
{
EVAL_HR(CoInitialize(NULL)
// Make sure MSXML 4.0 is installed
IXMLDOMDocument2Ptr pXMLDoc = NULL;
EVAL_HR(pXMLDoc.CreateInst
// Load the document synchronously
pXMLDoc->async = false;
VARIANT_BOOL varLoadResult = pXMLDoc->load(_T("C:\\oneg
// Load the XML document
if (varLoadResult)
{
pXMLDoc->setProperty("Sele
IXMLDOMNodeListPtr pEnglishNodes = pXMLDoc->selectNodes("/emp
for (long i=0; i<pEnglishNodes->Getlength
{
IXMLDOMNodePtr pEnglishNode = pEnglishNodes->Getitem(i);
pEnglishNode->Gettext();
pEnglishNode->GetnodeName(
printf("node name:%s, text:%s\n",
(LPCSTR)pEnglishNode->Getn
(LPCSTR)pEnglishNode->Gett
}
}
else
{// Load Failed
printMSXMLError(pXMLDoc);
}
}
catch(...)
{// Exception handling
}
CoUninitialize();
return 0;
}