dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: load xml from a path

  1. #1
    Join Date
    May 2015
    Posts
    213

    load xml from a path

    I have the following program to read xml, from the path where my application resides.
    But i want to be able to pick xml from specified path.

    Code:
    	HRESULT hr = CoInitialize(NULL);
    
    	MSXML2::IXMLDOMDocumentPtr pXMLDom;
    	MSXML2::IXMLDOMDocumentPtr pXSLDoc;
    	MSXML2::IXMLDOMDocumentPtr pXMLOut;
    
    	// Load the XML file. 
    	pXMLDom.CreateInstance(__uuidof(MSXML2::DOMDocument60), NULL, CLSCTX_INPROC_SERVER);
    
    
    	pXMLDom->async = VARIANT_FALSE; // The default is true. 
    	pXMLDom->validateOnParse = VARIANT_FALSE;
    	pXMLDom->resolveExternals = VARIANT_FALSE;
    
    	pXMLDom->load(L"C:\temp\xmlinputfile.xml");
    Last line is giving me an error. It works ok with

    pXMLDom->load(L"xmlinputfile.xml");

  2. #2
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    6,900

    Re: load xml from a path

    Last line is giving me an error.
    Well it will, won't it! What has been said repeatedly before about using single \ in path names?
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2019 (16.3.9)

  3. #3
    Join Date
    May 2015
    Posts
    213

    Re: load xml from a path

    Thanks a lot, i put the escape sequence for the single \. Sorry being bad student, i ask the same thing again and again !. Thanks a lot for your patience and help.

    the other issue is, i get the normal path as input for my program, and i need to load a specific xml from that path. I guess i need to convert the normal path and replace all single \ with the escape sequence. . It is getting complicated
    Last edited by pdk5; October 12th, 2019 at 07:59 AM.

  4. #4
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    6,900

    Re: load xml from a path

    If you are doing much work with paths, look at the facilities provided with C++ filesystem. See https://en.cppreference.com/w/cpp/header/filesystem - and in particular the filesystem:: path class.

    Also, consider using raw strings.

    "C:\\temp\\xmlinputfile.xml"

    as a raw string becomes

    R"(C:\temp\xmlinputfile.xml)"

    With only 1 \ ! However, be careful as using raw strings \n isn't a new line but the characters \ n etc.
    Last edited by 2kaud; October 12th, 2019 at 08:24 AM.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2019 (16.3.9)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)