2

I'm a bit stuck and new to C++. Basically I have an XML Document like this:

<Program>
 <DOSCommands>
   <Command>ipconfig /all</Command>
 </DOSCommands>
 <DOSCommands>
  <Command>chkdsk</Command>
 </DOSCommands>

 <Copy>
  <File>lol.txt</File>
 </Copy>
 <Copy>
  <File>BestMan.txt</File>
 </Copy>
</program>

Obviously my real XML contains lots of Copy and Dos tags. I have generated the code for this from the XML data binding. I can not seem to load these into my data structure properly. Can anyone point me in the right direction?

4
  • 1
    How does it fail to load? Do you get any errors (add them to the question in that case)? And most importantly, how do you load the file? Commented Jul 19, 2012 at 10:42
  • Provide more details about your project, like some code snippets... Commented Sep 10, 2012 at 13:53
  • "I have generated the code for this from the XML data binding." From what XML data binding? Commented Sep 12, 2012 at 20:15
  • <Program>...</program> (P versus p) is a typo I assume. Otherwise the error would be hilarious. Commented Dec 10, 2024 at 20:23

2 Answers 2

1

Unless this is a homework assignment, why not use a library like tinyxml2 and don't reinvent the wheel? It has a very nice c++ interface.

Sign up to request clarification or add additional context in comments.

Comments

0

Did you try the XML data binder in C++ Builder? If you have a sample XML file. It can made the data structures for your app to access it.

But your sample XML file should look a little like this:

<?xml version="1.0"?>
<log>
<Soft id="0">
    <DateTime>2024-12-10 12:58:49</DateTime>
    <Status>Info</Status>
    <Message>Auto start on - Connecting to HPU</Message>
</Soft>
<Soft id="1">
    <DateTime>2024-12-10 12:58:50</DateTime>
    <Status>Info</Status>
    <Message>Auto start off</Message>
</Soft>
<Soft id="2">
    <DateTime>2024-12-10 12:58:50</DateTime>
    <Status>Error</Status>
    <Message>Connection timed out!</Message>
</Soft>
</log>

Here is some code to read the file after you run the builder:

 int Me;
 String Testing;
 _di_IXMLlogType Test;
 _di_IXMLCAMSoftType Ok;

 Test = Getlog(XMLDocument1); // Loads my XML file from the TXMLDocument
 Me = Test->GetCount();  // finds the total number of records
 Ok = Test->Nodes[1];    // Loads the second node in the file
 Testing = Ok->Get_Message();

Loads the "Message" field from the record and loads it into a string (The get name will depends on your field names. IE my field was called "Message". I also have Get_Status and Get_Id)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.