-
October 13th, 2019, 01:58 AM
#1
xslt for filtering the xml
Hi,
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
thanks
pdk
-
October 13th, 2019, 06:45 AM
#2
Re: xslt for filtering the xml
I tried to add the following code:
Code:
MSXML2::IXMLDOMElementPtr ptr;
HRESULT hr = CoInitialize(NULL);
MSXML2::IXMLDOMDocumentPtr pXMLDom;
// Load the XML file.
pXMLDom.CreateInstance(__uuidof(MSXML2::DOMDocument60), NULL, CLSCTX_INPROC_SERVER);
pXMLDom->load(L"MODEL-LIST001.xml");
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);
-
October 13th, 2019, 12:43 PM
#3
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.
Code:
CoInitialize(NULL);
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");
pXMLDoc->load("MODEL-LIST001.xml");
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);
}
pXMLDomNode->get_childNodes(&pChildlist);
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|