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. Why is loadXML failing?

Why is loadXML failing?

Scheduled Pinned Locked Moved XML / XSL
helpquestion
6 Posts 4 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.
  • J Offline
    J Offline
    Jambolo
    wrote on last edited by
    #1

    What could be wrong here??? I get the error "Invalid at the top level of the document"; however, loading the exact same text from a file using load() works! CoInitialize(); CComPtr< IXMLDOMDocument2 > pDocument; pDocument.CoCreateInstance( CLSID_DOMDocument40, NULL, CLSCTX_INPROC_SERVER ); VARIANT_BOOL status; pDocument->loadXML( BSTR( "< ParticleSystem />" ), &status );

    R 1 Reply Last reply
    0
    • J Jambolo

      What could be wrong here??? I get the error "Invalid at the top level of the document"; however, loading the exact same text from a file using load() works! CoInitialize(); CComPtr< IXMLDOMDocument2 > pDocument; pDocument.CoCreateInstance( CLSID_DOMDocument40, NULL, CLSCTX_INPROC_SERVER ); VARIANT_BOOL status; pDocument->loadXML( BSTR( "< ParticleSystem />" ), &status );

      R Offline
      R Offline
      Retsof Nawor
      wrote on last edited by
      #2

      Without checking this out it may be because of the BSTR constructor you are using. BSTR's are unsigned short pointers, while you are passing in a const char* so a pointer cast is probably done (by the compiler) so two characters from your const char will be going into one character of the BSTR ie could be any character!! I suggest you try using CComBSTR, _bstr_t, or SysAllocString (and a matching free) to create your string to parse...

      J 1 Reply Last reply
      0
      • R Retsof Nawor

        Without checking this out it may be because of the BSTR constructor you are using. BSTR's are unsigned short pointers, while you are passing in a const char* so a pointer cast is probably done (by the compiler) so two characters from your const char will be going into one character of the BSTR ie could be any character!! I suggest you try using CComBSTR, _bstr_t, or SysAllocString (and a matching free) to create your string to parse...

        J Offline
        J Offline
        Jambolo
        wrote on last edited by
        #3

        Thanks for your help. I finally found that my problem was a combination of two different problems. 1. Here was the real problem: I was loading (as binary) a Unicode file that has a BOM (byte-order mark) at the front of the file. Then I passed the text to loadXML. Apparently, loadXML can't handle Unicode special characters. I consider this a bug in loadXML. 2. In order to test loadXML, I was creating a BSTR like this: BSTR( "< ParticleSystem />" ); Like you said, the constructor was not converting the string to a Unicode string as I expected it to do. loadXML was able to parse this: BSTR( L"< ParticleSystem />" );

        S M 2 Replies Last reply
        0
        • J Jambolo

          Thanks for your help. I finally found that my problem was a combination of two different problems. 1. Here was the real problem: I was loading (as binary) a Unicode file that has a BOM (byte-order mark) at the front of the file. Then I passed the text to loadXML. Apparently, loadXML can't handle Unicode special characters. I consider this a bug in loadXML. 2. In order to test loadXML, I was creating a BSTR like this: BSTR( "< ParticleSystem />" ); Like you said, the constructor was not converting the string to a Unicode string as I expected it to do. loadXML was able to parse this: BSTR( L"< ParticleSystem />" );

          S Offline
          S Offline
          Steve S
          wrote on last edited by
          #4

          If it's any consolation, I've hit that first problem too. My solution was to provide an IStream implementation that ate the BOM from it's input if present; it used memory mapped files so didn't ever call ReadFile... :-) Steve S

          1 Reply Last reply
          0
          • J Jambolo

            Thanks for your help. I finally found that my problem was a combination of two different problems. 1. Here was the real problem: I was loading (as binary) a Unicode file that has a BOM (byte-order mark) at the front of the file. Then I passed the text to loadXML. Apparently, loadXML can't handle Unicode special characters. I consider this a bug in loadXML. 2. In order to test loadXML, I was creating a BSTR like this: BSTR( "< ParticleSystem />" ); Like you said, the constructor was not converting the string to a Unicode string as I expected it to do. loadXML was able to parse this: BSTR( L"< ParticleSystem />" );

            M Offline
            M Offline
            Michael Dunn
            wrote on last edited by
            #5

            Jambolo wrote: BSTR( L"< ParticleSystem />" ); That is still not correct, you need to make a real BSTR or use a wrapper class like _bstr_t --Mike-- Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber CP SearchBar v2.0.2 released

            J 1 Reply Last reply
            0
            • M Michael Dunn

              Jambolo wrote: BSTR( L"< ParticleSystem />" ); That is still not correct, you need to make a real BSTR or use a wrapper class like _bstr_t --Mike-- Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber CP SearchBar v2.0.2 released

              J Offline
              J Offline
              Jambolo
              wrote on last edited by
              #6

              Michael Dunn wrote: Jambolo wrote: BSTR( L"< ParticleSystem />" ); That is still not correct, you need to make a real BSTR or use a wrapper class like _bstr_t Well, it worked just fine, so I'm not convinced. Regardless, I am using CComBSTR for the real code, but I will keep that in mind for next time.

              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