CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums
Results 1 to 3 of 3
  1. #1
    Join Date
    May 2015

    xslt for filtering the xml


    I have an xml of the following format:

    It has sections for different models. I just want to get the section for the model that is selected.

    I am looking for the xmlt to do this. and using the xml DOMmparser

    Name:  Example.jpg
Views: 557
Size:  68.0 KB

  2. #2
    Join Date
    May 2015

    Re: xslt for filtering the xml

    I tried to add the following code:
    	MSXML2::IXMLDOMElementPtr ptr;
    	HRESULT hr = CoInitialize(NULL);
    	MSXML2::IXMLDOMDocumentPtr pXMLDom;
    	// Load the XML file. 
    	pXMLDom.CreateInstance(__uuidof(MSXML2::DOMDocument60), NULL, CLSCTX_INPROC_SERVER);
    	ptr= pXMLDom->selectSingleNode("/MODEL-LIST/MODEL[@ID='450 MHz Default' and @TYPE='Enhanced Macrocell']/MODEL-PARAMS");
    But I am unable to set the params to 
        hr = pXMLDom->setProperty(BSTR(L"SelectionLanguage"), (CComVariant)L"XPath");
        hr = pXMLDom->setProperty((CComBSTR)"MaxElementDepth", (CComVariant)INT_MAX);

  3. #3
    Join Date
    May 2015

    Re: xslt for filtering the xml

    Found the way:
    I had asked somewhat similar Q earlier. and i had assumption that, i get this format for my program input. But was reviewing myself today, i just realised, i may need to do this extra parsing, in case i dont get the format i need.
    	IXMLDOMDocument2Ptr pXMLDoc = NULL;
    	MSXML2::IXMLDOMNodeListPtr pXMLDomNodeList;
    	BSTR bstrNodeValueParent = NULL;
    	BSTR bstrNodeValueChild = NULL;
    	IXMLDOMDocument2Ptr NewDoc = NULL;
    	HRESULT hr = pXMLDoc.CreateInstance(__uuidof(DOMDocument60));
    	pXMLDoc->setProperty("SelectionLanguage", "XPath");
    	BSTR bstrQueryTemp = SysAllocString(L"/MODEL-LIST/MODEL[@ID='450 MHz Default' and @TYPE='Enhanced Macrocell']");
    	pXMLDomNodeList = pXMLDoc->selectNodes(bstrQueryTemp);
    	MSXML2::IXMLDOMNodePtr pXMLDomNode;
    	pXMLDomNode = pXMLDoc->selectSingleNode(bstrQueryTemp);
    	bstr_t name = pXMLDomNode->GetnodeName();
    	//	bstr_t currentxml = ptr->Getxml();
    	MSXML2::IXMLDOMNamedNodeMapPtr pAttrs = pXMLDomNode->attributes;
    	MSXML2::IXMLDOMNodeList*                pChildlist = NULL;
    	long nAttrs = pAttrs->Getlength();
    	//Iterate through each Attribute found
    	for (long nAt = 0; nAt < nAttrs; nAt++)
    		MSXML2::IXMLDOMNodePtr pAttb = pAttrs->Getitem(nAt);
    		bstr_t bsAttbName = pAttb->nodeName;
    		bstr_t bsAttbValue = pAttb->text;
    	//	TRACE(_T("Attribute = %s is %s\n"), (LPTSTR)bsAttbName, (LPTSTR)bsAttbValue);
    	long size;
    	hr = pChildlist->get_length(&size);
    	for (int i = 0; i < size; i++)
    		MSXML2::IXMLDOMNodePtr pChild = pChildlist->Getitem(i);
    		bstr_t bsAttbName = pChild->nodeName;
    		bstr_t bsAttbValue = pChild->text;

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Click Here to Expand Forum to Full Width