Guest sullivanpt Posted November 12, 2004 Report Posted November 12, 2004 I know almost nothing about the MS XML document object model. I knew that a homescreen plugin was passed two IXMLDOMNode as parameters, and that every parsing example I could find used get_text to grab the text inside a label. All fine and dandy, except I wanted to implement variables within the label just like the calendar and messaging plug-ins do. (e.g. , etc.). The get_text function just strips these tags out, not the desired result. I spent a good many hours on this one and finally came to a solution. It may not be the "correct" solution. I'm posting this here in the hopes of saving someone else a few dozen hours. The trick (obvious to most maybe?) is to parse the tree all the way down, to the "text" node's children. There I found the text broken up and ordered, with the parsed XML variables in between. Example: SMS () actually parses as: lv 1, nd 1: label :: SMS () lv 2, nd 0: text :: SMS () lv 3, nd 0: (null) :: SMS ( lv 3, nd 1: unreadSMS :: lv 3, nd 2: (null) :: ) You can see that applying get_text to the "label" or "text" IXMLDOMNode (as they do in the samples) is useless. I needed to apply get_text to the unnamed nodes beneath the "text" attribute. I wrote the following function to help me figure this out: void ParseAndDumpTree(IXMLDOMNode* pnodeParams,int level) { int node = 0; BSTR bst,text; IXMLDOMNode* child = NULL; while(pnodeParams) { if(!FAILED(pnodeParams->get_baseName(&bst))) { if(!FAILED(pnodeParams->get_text(&text))) { DebugOut (TEXT("lv %d, nd %d: %s :: %sn"),level,node,bst,text); SysFreeString(text); // can free NULL safely } else DebugOut (TEXT("lv %d, nd %d: %sn"),level,node,bst); SysFreeString(bst); // can free NULL safely } if(!FAILED(pnodeParams->get_firstChild(&child))) ParseAndDumpTree(child,level+1); if(FAILED(pnodeParams->get_nextSibling(&pnodeParams))) // memory hole break; node++; } }
Guest bretto Posted February 1, 2005 Report Posted February 1, 2005 I had the same hassle so I just ended up grabbing the raw xml for the text node, stripping off the tags and doing a simple search and replace on the left over string. Not ideal I guess but effective enough the serve my purposes. Cheers Bretto
Guest DocBru Posted February 10, 2005 Report Posted February 10, 2005 I took the same approach as you. Parse the text node's child nodes. Another thing I was also struggling with is that get_text() trims the string, i.e. leadind and trailing spaces will be removed, which is annoying when you want to do variable substitution inside a string. I used get_nodeValue() instead. Thanks Bruno
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now