Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. XML / XSL
  4. A simple question about MSXML

A simple question about MSXML

Scheduled Pinned Locked Moved XML / XSL
xmlannouncementhtmldatabasehelp
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z Offline
    Z Offline
    zengkun
    wrote on last edited by
    #1

    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!

    U 1 Reply Last reply
    0
    • Z zengkun

      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!

      U Offline
      U Offline
      User 642242
      wrote on last edited by
      #2

      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");

      Z 1 Reply Last reply
      0
      • U User 642242

        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");

        Z Offline
        Z Offline
        zengkun
        wrote on last edited by
        #3

        Thank you for your help! This question has been resolved:laugh:.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups