LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

xml comment

Hi,
 
I'm parsing an XML Document using the CVIXML Library.  Is it possible to get the information from a comment?  An example of the text I would like to obtain is below:
 
<RootElement>
   <TestElement>
      <!-- I would like to obtain this text. -->
      ...
      ...
      ...
   </TestElement>
</RootElement>
 
Thanks in advance.
James.
0 Kudos
Message 1 of 3
(3,209 Views)

No. The CVIXML API only supports element and attribute nodes. The lower-level MSXML instrument that is called by the CVIXML API supports all node types and can be used to read the XML comment. Note that you can get the ActiveX handles used by MSXML API from the CVIXML handles and can mix calls to both the APIs, or you can program entirely using the MSXML API to read the comment text. The following is some simple code to look for XML comment nodes in a CVIXML element.

static void ParseForXMLComment(CVIXMLElement element)
{
 int       i, nChildren;
 MSXMLObj_IXMLDOMElement  handle = 0;
 MSXMLObj_IXMLDOMNodeList childList = 0;
 MSXMLObj_IXMLDOMNode  child = 0;
 
 CVIXMLGetElementActiveXHandle(element, &handle);
 MSXML_IXMLDOMElementGetchildNodes(handle, 0, &childList);
 MSXML_IXMLDOMNodeListGetlength(childList, 0, &nChildren);
 for (i = 0; i < nChildren; ++i)
 {
  MSXMLType_DOMNodeType type;
  MSXML_IXMLDOMNodeListGetitem(childList, 0, i, &child);
  MSXML_IXMLDOMNodeGetnodeType(child, 0, &type);
  if (type == MSXMLConst_NODE_COMMENT)
  {
   char * comment = 0;
   MSXML_IXMLDOMCommentGettext(child, 0, &comment);
   DebugPrintf("Comment: %s\n", comment);
   CA_FreeMemory(comment);
  }
  CA_DiscardObjHandle(child);
  child = 0;
 }
 
 CA_DiscardObjHandle(child);
 CA_DiscardObjHandle(childList);
 CA_DiscardObjHandle(handle);
}
Message 2 of 3
(3,191 Views)

Thanks Mohan!

Smiley Happy

This is exactly what I'm looking for.

 

James.

0 Kudos
Message 3 of 3
(3,176 Views)