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. Assign DTD to XML Document

Assign DTD to XML Document

Scheduled Pinned Locked Moved XML / XSL
c++linuxxmlhelpquestion
5 Posts 2 Posters 3 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.
  • B Offline
    B Offline
    Bash
    wrote on last edited by
    #1

    Hi Gurus! I'm a XML beginner. I try to save my program settings in XML file using Microsoft Visual C++ 6.0. Here is the sample from my code: -------------------------------------------------------------- IXMLDOMDocumentPtr XmlDocPtr; IXMLDOMNodePtr pNode; IXMLDOMElementPtr XmlRootPtr; b=XmlDocPtr->loadXML(_bstr_t("")); if (!b) return; XmlDocPtr->get_documentElement(&XmlRootPtr); if (XmlRootPtr) { VARIANT vtTemp2; vtTemp2.vt=VT_I2; vtTemp2.iVal = NODE_ELEMENT; pNode = XmlDocPtr->createNode(vtTemp2, "Program", ""); pNode->put_dataType(L"NODE_TEXT"); pNode->put_text(L"MYCOOLER"); XmlRootPtr->appendChild(pNode); pNode = XmlDocPtr->createNode(vtTemp2, "Distributor", ""); pNode->put_dataType(L"NODE_TEXT"); pNode->put_text(L"IBM Corp."); XmlRootPtr->appendChild(pNode); pNode = XmlDocPtr->createNode(vtTemp2, "Version", ""); pNode->put_dataType(L"NODE_TEXT"); pNode->put_text(L"6.0"); XmlRootPtr->appendChild(pNode); }; variant_t vDest(L"d:\\settings.xml"); XmlDocPtr->save(vDest); -------------------------------------------------------------- File d:\system.dtd contains: -------------------------------------------------------------- -------------------------------------------------------------- But resulted file "settings.xml" is not formatted according system.dtd specification. What's wrong? Help me! Yours sincerely, Alex Bash

    S 1 Reply Last reply
    0
    • B Bash

      Hi Gurus! I'm a XML beginner. I try to save my program settings in XML file using Microsoft Visual C++ 6.0. Here is the sample from my code: -------------------------------------------------------------- IXMLDOMDocumentPtr XmlDocPtr; IXMLDOMNodePtr pNode; IXMLDOMElementPtr XmlRootPtr; b=XmlDocPtr->loadXML(_bstr_t("")); if (!b) return; XmlDocPtr->get_documentElement(&XmlRootPtr); if (XmlRootPtr) { VARIANT vtTemp2; vtTemp2.vt=VT_I2; vtTemp2.iVal = NODE_ELEMENT; pNode = XmlDocPtr->createNode(vtTemp2, "Program", ""); pNode->put_dataType(L"NODE_TEXT"); pNode->put_text(L"MYCOOLER"); XmlRootPtr->appendChild(pNode); pNode = XmlDocPtr->createNode(vtTemp2, "Distributor", ""); pNode->put_dataType(L"NODE_TEXT"); pNode->put_text(L"IBM Corp."); XmlRootPtr->appendChild(pNode); pNode = XmlDocPtr->createNode(vtTemp2, "Version", ""); pNode->put_dataType(L"NODE_TEXT"); pNode->put_text(L"6.0"); XmlRootPtr->appendChild(pNode); }; variant_t vDest(L"d:\\settings.xml"); XmlDocPtr->save(vDest); -------------------------------------------------------------- File d:\system.dtd contains: -------------------------------------------------------------- -------------------------------------------------------------- But resulted file "settings.xml" is not formatted according system.dtd specification. What's wrong? Help me! Yours sincerely, Alex Bash

      S Offline
      S Offline
      Stephane Rodriguez
      wrote on last edited by
      #2

      Bash wrote: But resulted file "settings.xml" is not formatted according system.dtd specification. The DTD is not a formatter. A DTD is just here to verify the well-formedness and/or validness of an Xml stream. The formatting is the result of your own code (appendChild, ...). On top of that, when you open an Xml file in MSIE, MSIE applies a default formatting (using a XSLT stylesheet) : for instance it may show you <k name="kkk"/> although there is <k name="kkk"></k> in the file.


      Back to real work : D-27.

      B 1 Reply Last reply
      0
      • S Stephane Rodriguez

        Bash wrote: But resulted file "settings.xml" is not formatted according system.dtd specification. The DTD is not a formatter. A DTD is just here to verify the well-formedness and/or validness of an Xml stream. The formatting is the result of your own code (appendChild, ...). On top of that, when you open an Xml file in MSIE, MSIE applies a default formatting (using a XSLT stylesheet) : for instance it may show you <k name="kkk"/> although there is <k name="kkk"></k> in the file.


        Back to real work : D-27.

        B Offline
        B Offline
        Bash
        wrote on last edited by
        #3

        Hi, Thank you for quick reply to the beginner. ;) And another question - how to insert CR/LF symbol after appending a new child. At present, I have "settings.xml" with single line like as: MYCOOLERIBM Corp.6.0 I want to get this xml (i.e. "formatted") as follows: MYCOOLER IBM Corp. 6.0 How to do "formatted" xml? Yours sincerely, Alex Bash

        S 1 Reply Last reply
        0
        • B Bash

          Hi, Thank you for quick reply to the beginner. ;) And another question - how to insert CR/LF symbol after appending a new child. At present, I have "settings.xml" with single line like as: MYCOOLERIBM Corp.6.0 I want to get this xml (i.e. "formatted") as follows: MYCOOLER IBM Corp. 6.0 How to do "formatted" xml? Yours sincerely, Alex Bash

          S Offline
          S Offline
          Stephane Rodriguez
          wrote on last edited by
          #4

          Unfortunately, there is no way to do so using MSXML. That's probably why this SDK is now legacy and replaced by a much more powerful Xml stuff along with .NET. You can achieve indentation by creating your own fake text nodes, with code like this :

          var dom = new ActiveXObject("Microsoft.XMLDOM");
          var root = dom.createElement("toto");
          for (i = 0; i < 10; i++) {
          var formatting = dom.createTextNode("\n\t");
          root.appendChild(formatting);
          var child = dom.createElement(child);
          root.appendChild(child);
          }
          dom.save("output.xml");


          Back to real work : D-27.

          B 1 Reply Last reply
          0
          • S Stephane Rodriguez

            Unfortunately, there is no way to do so using MSXML. That's probably why this SDK is now legacy and replaced by a much more powerful Xml stuff along with .NET. You can achieve indentation by creating your own fake text nodes, with code like this :

            var dom = new ActiveXObject("Microsoft.XMLDOM");
            var root = dom.createElement("toto");
            for (i = 0; i < 10; i++) {
            var formatting = dom.createTextNode("\n\t");
            root.appendChild(formatting);
            var child = dom.createElement(child);
            root.appendChild(child);
            }
            dom.save("output.xml");


            Back to real work : D-27.

            B Offline
            B Offline
            Bash
            wrote on last edited by
            #5

            Thank you, it works! Yours sincerely, Alex Bash

            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