|
I have to parse RSS channel definition XML file. I have appended one sample at the end of this topic.
I have installed MSXML parser 6 and uses it successfully. Please refer to function XmlRSSRead.
There are a lot of information about the channel and item of this channel. For example, one channel has title, link, description information. One channel may have a lot of item too. Each item also hase title, link, description information.
I have to extract title, link, description information in my application. I can not find one quick start guide from microsoft doucments.
Could anyone be kind to tell me what I should do next?
The following is the function I have now and the xml file I want to parse.
void XmlRSSRead( void )
{
//¡ä¡ä?¡§DOMDocument???¨®
MSXML2::IXMLDOMDocumentPtr pDoc;
HRESULT hr = pDoc.CreateInstance(__uuidof(MSXML2::DOMDocument30));
if(!SUCCEEDED(hr))
{
AfxMessageBox( _T("?T¡¤¡§¡ä¡ä?¡§DOMDocument???¨®¡ê????¨¬2¨¦¨º?¡¤?¡ã2¡Á¡ã¨¢?MS XML Parser ??DD?a!") );
}
//?¨®?????t
pDoc->load( _T("D:\\temp\\mPhone\\Docs\\RSS\\nature.xml") );
//?¨²¨º¡Â?D2¨¦?¨°???achannel¦Ì??¨²¦Ì?,
// "//"¡À¨ª¨º??¨²¨¨?¨°a¨°?2?2¨¦?¨°
MSXML2::IXMLDOMElementPtr childNode ;
childNode = (MSXML2::IXMLDOMElementPtr)(pDoc->selectSingleNode("//channel"));
//¦Ì?¦Ì??¨²¦Ì?¨¤¨¤D¨ª
MSXML2::DOMNodeType nodeType;
childNode->get_nodeType(&nodeType);
//?¨²¦Ì???3?
BSTR var;
CString name;
childNode->get_nodeName(&var);
name = (char*)(_bstr_t)var;
//?¨²¦Ì??¦Ì
VARIANT varVal;
childNode->get_nodeTypedValue(&varVal);
CString strValue = (char*)(_bstr_t)varVal;
//?¨²¦Ì?¨º?D?,¡¤??¨²¨¢¡ä¡À¨ª?D
MSXML2::IXMLDOMNamedNodeMapPtr pAttrs = NULL;
MSXML2::IXMLDOMNodePtr pAttrItem;
childNode->get_attributes(&pAttrs);
long nCount ;
pAttrs->get_length(&nCount);
for(int i = 0 ; i < nCount ; i++)
{
pAttrs->get_item(i,&pAttrItem);
//?¨°???¨¦¨°?¨ª¡§1yo¡¥¨ºyget_nodeName,get_nodeTypedValue¦Ì?¦Ì?¨º?D???o¨ª¨º?D??¦Ì
//¨°2?¨¦¨°??¡À?¨®¦Ì?¦Ì?
CString strAttrName = (char*)(_bstr_t)pAttrItem->nodeName;
CString strAttrValue = (char*)(_bstr_t)pAttrItem->nodeTypedValue;
}
}
void mfXmlReadTest( void )
{
::CoInitialize(NULL);
MSXML2::IXMLDOMDocumentPtr spPtr;
HRESULT hr = spPtr.CreateInstance(__uuidof(MSXML2::DOMDocument30));
ASSERT(SUCCEEDED(hr));
spPtr->loadXML("<r>\n<t>top\nbottom\n");
spPtr->save("C:\\nature.xml");
spPtr.Release();
::CoUninitialize();
}
XMLÎļþÈçÏ£º
<rss xmlns:itunes="http://www.itunes.com/DTDs/Podcast-1.0.dtd" version="2.0">
<channel>
<title>Nature Podcast
http://www.nature.com/nature/podcast/rss/nature.xml <description>Nature is a weekly international journal publishing the finest peer-reviewed research in all fields of science. The Nature Podcast is a free weekly audio show highlighting content from each issue, and interviews with the scientists creating the data. The Nature Podcast provides insight and context to groundbreaking research, and allows the scientists to explain the significance of their work in their own words.
<language>en
<copyright>© 2006 Nature Publishing Group
<lastbuilddate>Wed, 25 Jul 2007 18:00:00 GMT
<category>Science & Medicine
<category>Technology
<url>http://www.nature.com/nature/podcast/images/nature_rss_logo.png
<title>Nature
http://www.nature.com/nature/podcast/rss/nature.xml <width>144
<height>144
<itunes:author>Nature
<itunes:subtitle>Interviews, insight and highlights of the latest scientific discoveries, every week in Nature
<itunes:summary>Nature is a weekly international journal publishing the finest peer-reviewed research in all fields of science. The Nature Podcast is a free weekly audio show highlighting content from each issue, and interviews with the scientists creating the data. The Nature Podcast provides insight and context to groundbreaking research, and allows the scientists to explain the significance of their work in their own words.
<itunes:owner>
<itunes:name>Nature
<itunes:email>podcast@nature.com
<itunes:category text="Science & Medicine">
<itunes:category text="Technology">
<itunes:image href="http://www.nature.com/nature/podcast/images/nature_itunes_logo.png">
<item>
<title>Nature Podcast: 26 July 2007
http://www.nature.com/nature/podcast/v448/n7152/nature-2007-07-26.mp3 <description>?26 July: Rain changes of our own making, science in the Simpsons, Californian-style plate rifts, investigating inflammatory bowel disease, pygmies with palm pilots.
<guid>http://www.nature.com/nature/podcast/v448/n7152/nature-2007-07-26.mp3
<enclosure url="http://www.nature.com/nature/podcast/v448/n7152/nature-2007-07-26.mp3" length="13343922" type="audio/mpeg">
<pubdate>Wed, 25 Jul 2007 18:00:00 GMT
<category>Science & Medicine
<category>Technology
<itunes:author>Nature
<itunes:subtitle>?26 July: Rain changes of our own making, science in the Simpsons, Californian-style plate rifts, investigating inflammatory bowel disease, pygmies with palm pilots.
<itunes:duration>37:03
<itunes:explicit>no
<itunes:category text="Science & Medicine">
<itunes:category text="Technology">
<itunes:keywords>nature, podcast, science, technology, education, science news, biology, physics, genetics, astronomy, astrophysics, quantum physics, evolution, evolutionary biology, geophysics, climate change, earth science, materials science, science policy, medicine, systems biology, genomics, palaeobiology, ecology, molecular biology, cancer, immunology, pharmacology, developmental biology, biochemistry, bioinformatics, nanotechnology, biotechnology, drug discovery, environmental science, life, marine biology, medical research, neuroscience, rna, dna, cell cycle, signal transduction, cell signalling
|
|
|
|
|
I would generally use selectNodes or selectSingleNode with an XPath expression to find particular information in an XML document.
DoEvents : Generating unexpected recursion since 1991
|
|
|
|
|
hi,
I've added a set of strings(from Database) to my combo box using
membervariable.AddString(CString)
Now,How can i add a set of integers to my combo box.
Can any one tell mi a solution for this...with a clear example(as i'm a beginner).
if so please tell me how to add the floats to the same..
thank you in advance..........
|
|
|
|
|
You can convert your numeric types to strings...
int i = 42;
CString str;
str.Format(_T("%d"), i);
m_combobox.AddString(str);
double d = 1.23456;
CString str;
str.Format(_T("%.3f"), d);
m_combobox.AddString(str);
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
hai mark,
even i wanted to suggest the same,but before hitting reply, i saw your name ,got diverted towards your post, and dropped my idea.
your post is more descriptive.
Mark Salsbery wrote: str.Format(_T("%d"), i);
can you please explain me why you have used _T there.
thank you.
Suggestion to the members:
prefix your main thread subject with [SOLVED] if it is solved.
chandu.
|
|
|
|
|
chandu004 wrote: can you please explain me why you have used _T there.
I use the generic text mappings everywhere.
In this case, I'm using a CString, which is a generic type
(unlike CStringA and CStringW).
CString::Format() takes a PCXSTR as its first argument so I
use _T() to get that type.
This will compile on both Unicode and non-Unicode builds...
that's the whole idea
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
|
thanks mark.
i feel that, observing your posts one day is equalent to reading one book per day.
Suggestion to the members:
prefix your main thread subject with [SOLVED] if it is solved.
chandu.
|
|
|
|
|
Of course sometime forums are better than books like this forum.
|
|
|
|
|
I hope this is the correct forum, I use Borland's TMemo textpad and want to know the character position of my mouse cursor, so in MouseMove I do the following:
// X and Y are in client space
void __fastcall MyApp::Memo1MouseMove(TObject *Sender, TShiftState Shift, int X, int Y)
{
TPoint mousePos;
mousePos.x = X;
mousePos.y = Y;
int charPos = SendMessage(Memo1->Handle, EM_CHARFROMPOS, 0, (LPARAM)&mousePos);
}
The problem is charPos is always -1, even when I move the mouse over text in the Memo. Any ides whats wrong?
|
|
|
|
|
I'm guessing your cursor coordinates passed to MyApp::Memo1MouseMove()
are in screen coordinates but the EM_CHARFROMPOS message expects coords
relative to the client area of the edit control.
What happens if you do this...
void __fastcall MyApp::Memo1MouseMove(TObject *Sender, TShiftState Shift, int X, int Y)
{
TPoint mousePos;
mousePos.x = X;
mousePos.y = Y;
<font color="Red">ScreenToClient(</font>Memo1->Handle, &mousePos<font color="Red">);</font>
int charPos = SendMessage(Memo1->Handle, EM_CHARFROMPOS, 0, (LPARAM)&mousePos);
}
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
nope, the X and Y I get are in client coordinates. Yet I tried ScreenToClient just for fun, with no luck though.
|
|
|
|
|
Hmm... It was worth a shot.
I don't remember TMemo - is it really a windows edit control or
rich edit control? If not, the message may not work (unless the
window is designed to handle the message the same as the Windows
common controls does).
Otherwise, the only reason -1 should be returned is if the cursor
is not in the client area of the control.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
It is an edit control. Maybe that is the problem then? That would be bad, I have based all my code on this control...
The cursor is inside the client, I get correct mouse positions...
|
|
|
|
|
Try this:
// X and Y are in client space
void __fastcall MyApp::Memo1MouseMove(TObject *Sender, TShiftState Shift, int X, int Y)
{
int charPos = SendMessage(Memo1->Handle, EM_CHARFROMPOS, 0, MAKELPARAM((WORD)x,(WORD)y));
}
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Yes! That worked, thanks a lot!
I had actually read somewhere that there was a bug in MAKELPARAM that would sometimes throw an exception but it seems to work fine for me, thanks again.
|
|
|
|
|
LejonO wrote: I had actually read somewhere that there was a bug in MAKELPARAM that would sometimes throw an exception
I don't think that's possible - it's just a macro that does some bitwise
operations on the arguments
Cheers,
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
hai all,
can anybody suggest me some api, using which, we can automate MS word?
i should be able to create a word file,
write some data to it,
insert images and grids to it.
is it possible?
suggestions please.
Suggestion to the members:
prefix your main thread subject with [SOLVED] if it is solved.
chandu.
|
|
|
|
|
chandu004 wrote: can anybody suggest me some api, using which, we can automate MS word?
Yes the Word Object Model. You can find the documentation on the MSDN site. Realize that today there will likely be more documentation for .NET development than for native C++.
|
|
|
|
|
Hello Friends,
I want my application to run in the background. And it displays only when some cliked in taskbar icon.
But I am not getting where to put the ShowWindow(hWnd,SW_HIDE); to hide the window.so that it doesn't appeare when It is loaded at startup.(I have set the registry, so that it runs at startup).
I have tryed to put it in following places but getting errors.
case WM_INITDIALOG:
{
//If I use the ShowWindow in the begining of the WM_INITDIALOG.
//I am geeting 02 as Error Code. Which Means "The system cannot find the file specified. "
if( ! ShowWindow(hWndDlg,SW_HIDE) ) //Hide the main window
dError = GetLastError();
...
...
//If I use the ShowWindow at the End of the WM_INITDIALOG.
//I am geeting 170 as Error Code. Which Means "The requested resource is in use."
if( ! ShowWindow(hWndDlg,SW_HIDE) ) //Hide the main window
dError = GetLastError();
}
|
|
|
|
|
Why you dont set your program to minimize when its running?
|
|
|
|
|
GauranG33 wrote: .(I have set the registry, so that it runs at startup).
can you please guide me how you have achieved this.
this is great because, i have been trying this since a couple of months but in vain.
and to your question, i have temporary solution.
1.set the dialog properties in such a way that, it does not have any border.
so that, it will be always running in the background, and gets displayed only if the user clicks the icon in the taskbar.
2.if you know, how to track the GetFocus and Lost Focus events, then, i can suggest a better solution.
gud luck.
Suggestion to the members:
prefix your main thread subject with [SOLVED] if it is solved.
chandu.
|
|
|
|
|
|
Why not just create the main window without the WS_VISIBLE flag
so you don't have to worry about hiding it?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
If this solution is taken... The controls can not be used while the window is invisible, but if you use other things as triggers (for example a timer) then the code will be called anyways.
Am I right?
But if you make the WS_VISIBLE away, and in some conditions need the window another time... can you make it visible with the ShowWindow (TRUE) ??? Or won't be posible because the property has not been set?
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
|
|
|
|
|