Dear all,
I'm trying to search for "width" and "height" in the root node in an SVG doc
and remove them accordingly, what I don't understand is if I did the
following code, it'll only remove "width" (the earlier in the attr list) in
<svg ... width="..." height="..." > and height is left untouched.
// SVG DOM Root
MSXML2::IXMLDOMElementPtr pDoc = pDom->documentElement;
MSXML2::IXMLDOMNamedNodeMapPtr pNamedNodeMap = NULL;
MSXML2::IXMLDOMNodePtr pRemovedNode = NULL;
pNamedNodeMap = pDoc->Getattributes();
CComBSTR attrWidth("width");
CComBSTR attrHeight("height");
for (int numAttr = 0; numAttr < pNamedNodeMap->Getlength(); numAttr++) {
BSTR attrName = pNamedNodeMap->Getitem(numAttr)->GetnodeName();
CComBSTR bstrAttrName;
bstrAttrName.AppendBSTR(attrName);
if ( bstrAttrName == attrWidth || bstrAttrName == attrHeight )
pRemovedNode = pNamedNodeMap->removeNamedItem(attrName);
bstrAttrName.Empty();
pRemovedNode = NULL;
}
But if I did the following, they're both removed... I don't understand why I
have to do 2 passes?
// Create SVG DOM Root
MSXML2::IXMLDOMElementPtr pDoc = pDom->documentElement;
// Remove any width/height attrs in svg (mattercast)
MSXML2::IXMLDOMNamedNodeMapPtr pNamedNodeMap = NULL;
MSXML2::IXMLDOMNodePtr pRemovedNode = NULL;
pNamedNodeMap = pDoc->Getattributes();
CComBSTR attrWidth("width");
CComBSTR attrHeight("height");
for (int numAttr = 0; numAttr < pNamedNodeMap->Getlength(); numAttr++) {
BSTR attrName = pNamedNodeMap->Getitem(numAttr)->GetnodeName();
CComBSTR bstrAttrName;
bstrAttrName.AppendBSTR(attrName);
if (bstrAttrName == attrWidth) pRemovedNode =
pNamedNodeMap->removeNamedItem(attrName);
bstrAttrName.Empty();
pRemovedNode = NULL;
}
for (numAttr = 0; numAttr < pNamedNodeMap->Getlength(); numAttr++) {
BSTR attrName = pNamedNodeMap->Getitem(numAttr)->GetnodeName();
CComBSTR bstrAttrName;
bstrAttrName.AppendBSTR(attrName);
if (bstrAttrName == attrHeight) pRemovedNode =
pNamedNodeMap->removeNamedItem(attrName);
bstrAttrName.Empty();
pRemovedNode = NULL;
}
Very confused... please enlighten...
Thanks, Juliues