Watch, Follow, &
Connect with Us

Please visit our new home
community.embarcadero.com.


Welcome, Guest
Guest Settings
Help

Thread: dynamic XMLDocument


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 2 - Last Post: Feb 8, 2018 9:58 AM Last Post By: Remy Lebeau (Te... Threads: [ Previous | Next ]
bernard tran

Posts: 31
Registered: 2/24/06
dynamic XMLDocument  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 8, 2018 6:33 AM
const _di_IXMLDocument document = interface_cast<Xmlintf::IXMLDocument> (new TXMLDocument(NULL));
document->LoadFromFile("c:\test.xml");
const _di_IXMLNode node = document->DocumentElement->ChildNodes->FindNode("Settings");

Run fine if debug mode
Violation address access at 000000000442D964 error if run mode

Rad studio 10.2 Tokyo, FMX application, c++ x64

Don't want to use a dropped XML component in the form, need to create a dynamic XMLDocument

All sample code i've found in Embercadero website don't work in run mode. Only work in debug mode.

What's wrong in my code ?
Antonio Estevez

Posts: 665
Registered: 4/12/00
Re: dynamic XMLDocument  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 8, 2018 8:34 AM   in response to: bernard tran in response to: bernard tran
El 08/02/2018 a las 15:33, bernard tran escribió:
const _di_IXMLDocument document = interface_cast<Xmlintf::IXMLDocument> (new TXMLDocument(NULL));
document->LoadFromFile("c:\test.xml");
const _di_IXMLNode node = document->DocumentElement->ChildNodes->FindNode("Settings");

Run fine if debug mode
Violation address access at 000000000442D964 error if run mode

Rad studio 10.2 Tokyo, FMX application, c++ x64

Don't want to use a dropped XML component in the form, need to create a dynamic XMLDocument

All sample code i've found in Embercadero website don't work in run mode. Only work in debug mode.

What's wrong in my code ?

Try this:

#include <Xml.XMLDoc.hpp>
...
   _di_IXMLDocument document= NewXMLDocument();
   document->LoadFromFile(_D("c:\\test.xml"));
 
   _di_IXMLNode node= document->DocumentElement->ChildNodes->FindNode(_D("Settings"));


Or

#include <Xml.XMLDoc.hpp>
...
    _di_IXMLDocument document= LoadXMLDocument(_D("c:\\test.xml"));
    _di_IXMLNode node= document->DocumentElement->ChildNodes->FindNode(_D("Settings"));


Note that the backslash is scaped in the file name's literal string
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: dynamic XMLDocument  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 8, 2018 9:58 AM   in response to: bernard tran in response to: bernard tran
bernard tran wrote:

const _di_IXMLDocument document =
interface_cast<Xmlintf::IXMLDocument> (new TXMLDocument(NULL));

You should be using the NewXMLDocument() function instead of
constructing the TXMLDocument object manually:

http://docwiki.embarcadero.com/Libraries/en/Xml.XMLDoc.NewXMLDocument

const _di_IXMLDocument document = NewXMLDocument();


document->LoadFromFile("c:\test.xml");

You need to escape backslashes in string literals:

"c:\\test.xml"


Also, LoadFromFile() expects a System::String, which is an alias for
System::UnicodeString in CB2009 and later. And while a UnicodeString
can be constructed from a char* string, doing so requires a runtime
conversion of the character data instead of merely assigning the data
as-is.

I suggest you use the _D() macro to ensure that your string literal
uses the same character type that System::String uses:

document->LoadFromFile(_D("c:\\test.xml"));


const _di_IXMLNode node =
document->DocumentElement->ChildNodes->FindNode("Settings");

Same for the FindNode() parameter:

FindNode(_D("Settings"));


--
Remy Lebeau (TeamB)
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02