A simple question about MSXML
-
I want to use MSXML to create a XML file like this Here is my source coede #include #import using namespace MSXML2; int main(int argc, char* argv[]) { IXMLDOMDocument2Ptr pXMLDom; HRESULT hr; CoInitialize(NULL); hr = pXMLDom.CreateInstance(__uuidof(DOMDocument40)); if (FAILED(hr)) { printf("Failed to CreateInstance on an XML DOM"); return NULL; } pXMLDom->preserveWhiteSpace = VARIANT_TRUE; IXMLDOMProcessingInstructionPtr pi; pi = pXMLDom->createProcessingInstruction("xml", "version='1.0' encoding='UTF-8'"); if (pi != NULL) { pXMLDom->appendChild(pi); pi.Release(); } IXMLDOMElementPtr pe; IXMLDOMNodePtr nodePtr; _variant_t varTyp((short)NODE_ELEMENT); nodePtr=pXMLDom->createNode(varTyp,"Schema","http://www.w3.org/2001/XMLSchema"); pXMLDom->appendChild(nodePtr); nodePtr.Release(); pe = pXMLDom->documentElement; IXMLDOMAttributePtr pa; pXMLDom->documentElement->appendChild(pXMLDom->createTextNode("\n\t")); IXMLDOMDocumentFragmentPtr pdf; pdf = pXMLDom->createDocumentFragment(); pe = pXMLDom->createElement("element"); pe->setAttribute("name","Features"); pe->setAttribute("type","wfs:featuresType"); pe->setAttribute("substitutionGroup","gml:_FeatureCollection"); pdf->appendChild(pe); pe.Release(); pXMLDom->documentElement->appendChild(pdf); pdf.Release(); pXMLDom->documentElement->appendChild(pXMLDom->createTextNode("\n\t")); hr = pXMLDom->save("dynaDom.xml"); if (FAILED(hr)) { printf("Failed to save DOM to dynaDom.xml\n"); } else { printf("DOM saved to dynamDom.xml\n"); } if (pXMLDom) pXMLDom.Release(); CoUninitialize(); return 0; } But the output is: you can see that :there is an attribute "xmlns" within the "element" tag and the value of the attribute is nothing. I don't want the out come is this,Please Help!
-
I want to use MSXML to create a XML file like this Here is my source coede #include #import using namespace MSXML2; int main(int argc, char* argv[]) { IXMLDOMDocument2Ptr pXMLDom; HRESULT hr; CoInitialize(NULL); hr = pXMLDom.CreateInstance(__uuidof(DOMDocument40)); if (FAILED(hr)) { printf("Failed to CreateInstance on an XML DOM"); return NULL; } pXMLDom->preserveWhiteSpace = VARIANT_TRUE; IXMLDOMProcessingInstructionPtr pi; pi = pXMLDom->createProcessingInstruction("xml", "version='1.0' encoding='UTF-8'"); if (pi != NULL) { pXMLDom->appendChild(pi); pi.Release(); } IXMLDOMElementPtr pe; IXMLDOMNodePtr nodePtr; _variant_t varTyp((short)NODE_ELEMENT); nodePtr=pXMLDom->createNode(varTyp,"Schema","http://www.w3.org/2001/XMLSchema"); pXMLDom->appendChild(nodePtr); nodePtr.Release(); pe = pXMLDom->documentElement; IXMLDOMAttributePtr pa; pXMLDom->documentElement->appendChild(pXMLDom->createTextNode("\n\t")); IXMLDOMDocumentFragmentPtr pdf; pdf = pXMLDom->createDocumentFragment(); pe = pXMLDom->createElement("element"); pe->setAttribute("name","Features"); pe->setAttribute("type","wfs:featuresType"); pe->setAttribute("substitutionGroup","gml:_FeatureCollection"); pdf->appendChild(pe); pe.Release(); pXMLDom->documentElement->appendChild(pdf); pdf.Release(); pXMLDom->documentElement->appendChild(pXMLDom->createTextNode("\n\t")); hr = pXMLDom->save("dynaDom.xml"); if (FAILED(hr)) { printf("Failed to save DOM to dynaDom.xml\n"); } else { printf("DOM saved to dynamDom.xml\n"); } if (pXMLDom) pXMLDom.Release(); CoUninitialize(); return 0; } But the output is: you can see that :there is an attribute "xmlns" within the "element" tag and the value of the attribute is nothing. I don't want the out come is this,Please Help!
When you create the "element" node you need so specify that it is part of the same namspace as the Schema element. Otherwise what you are saying is that the element node does not belong to any namespace, hence the empty xmlns attribute. Something like : pXMLDom->createElement("element",","http://www.w3.org/2001/XMLSchema");
-
When you create the "element" node you need so specify that it is part of the same namspace as the Schema element. Otherwise what you are saying is that the element node does not belong to any namespace, hence the empty xmlns attribute. Something like : pXMLDom->createElement("element",","http://www.w3.org/2001/XMLSchema");