Click to See Complete Forum and Search --> : How to re-organized XML file and call XML file from my software


bella_11041988
05-11-2006, 04:22 AM
Hello, everybody. Sorry to disturb you all.
Currently, I have a speech recording and playback software developed by Microsoft Visual C++ 6.0. The software is used to train children with speech problem and scores will be calculated and showed at the end of each practice session. The software is able to record and playback real-time.

Children use this software at home and save their practice records in a single floppy disk. Then, children will bring the floppy disk with practice records inside when they return to our centre.

I have two problems with the xml programming part. My software automatically created history file (in XML format) to display the scores of the children’s practices. The history file (in XML format) is saved by the children in floppy disk when they return to our centre.
But, the data or information in the XML is in a mess where all data are put together. Do you mind to tell me what should I do to create more organized XML format? The therapist needs to scroll in order to read the scores. I have the program codes of XML in four of my cpp files.

The second question is how to call or open XML file (the history file) from my software?
My codes are as below. After I execute the program, it is error free and the File Open dialog box is popped up but no XML file came out after I select the desired XML file. My codes are as below:

void CSpeechDlg::OnScore()
{
// TODO: Add your command handler code here
CFileDialog openfile(TRUE,NULL,NULL,OFN_OVERWRITEPROMPT,"XML File (*.xml)|*.xml|");
if (openfile.DoModal()==IDOK)
{
CString cs=openfile.GetFileName();
char* filename=new char[cs.GetLength()+1];
strcpy(filename,cs);
}

}

I promise I wont disturb you a lot, I promise I will do my best. Can you please help me?
I am totally new to this as the software is written by one of my previous friend who worked together with me in a voluntary speech rehabilitation centre. We need this software to train children in the centre. I work part time there.

Hope you can give me some guidances on how to do it. I promise I can learn as independent as possible but I really need your guidance at this very beginning, please.
Please, I really appreciate all your help.

Stephen Philbin
05-11-2006, 09:45 AM
Hehe, don't worry about asking questions. It's the best way of learning and what this place is here for. Although Microsofts Visual C++ 6.0 isn't what this place is for, so I'm not so sure you're going to find many people here that will have the knowledge to help you. I know I certainly don't know anything about it.

Don't worry though. Help is at hand! :D Jupiter Media (That's the folks that own this place) also have another forum for exactly this subject. Try the Code Guru (http://www.codeguru.com/forum/) forums and ask about your problem there. There's bound to be someone there that knows how to open XML files from Microsoft's Visual C++ 6.0.

A little extra info:
I suggested going to the Code Guru (http://www.codeguru.com/forum/) forums only because your question was about how to use a particular language with XML. The XML Recommendation (basically the specification for XML) doesn't say how languages should interact with XML (like how to load documents and things), it only dictates how XML its self should behave and work. If you have any more questions about XML or XSL or XPath or anything like that, which are about XML its self (like the XML code), then don't hesitate to ask here. ;)

Sorry if I've caused any confusion.

bella_11041988
05-11-2006, 09:38 PM
Hehe, don't worry about asking questions. It's the best way of learning and what this place is here for. Although Microsofts Visual C++ 6.0 isn't what this place is for, so I'm not so sure you're going to find many people here that will have the knowledge to help you. I know I certainly don't know anything about it.

Don't worry though. Help is at hand! :D Jupiter Media (That's the folks that own this place) also have another forum for exactly this subject. Try the Code Guru (http://www.codeguru.com/forum/) forums and ask about your problem there. There's bound to be someone there that knows how to open XML files from Microsoft's Visual C++ 6.0.

A little extra info:
I suggested going to the Code Guru (http://www.codeguru.com/forum/) forums only because your question was about how to use a particular language with XML. The XML Recommendation (basically the specification for XML) doesn't say how languages should interact with XML (like how to load documents and things), it only dictates how XML its self should behave and work. If you have any more questions about XML or XSL or XPath or anything like that, which are about XML its self (like the XML code), then don't hesitate to ask here. ;)

Sorry if I've caused any confusion.

Hi, Stephen Philbin, thanks so much for your reply, appreciate.

My questions are:

1. I failed to use the above codes to open a XML file, I dont know what's wrong with the codes.

2. I attached the XML file created by my program. As you can see, it is created in an unorganized format. I hope it can be created with spacing between sentences so that it can be more easier to read. And, I hope therapist does not need to scroll to the far right end in order to read the children's scoring.

I really need your help at this very beginning, please help, please.

Stephen Philbin
05-12-2006, 12:21 PM
I've looked at your XML file and I think I see the problem. There is a good chance there is nothing wrong with your visual C++ code that is trying to open the file, I think it just is not recognising the file as an XML file. This is because technically speaking, it is not an xml file. The XML prolog is not complete and there is no document element.

I've taken your example file and made a new example file (http://www.dootdootdoodydoodydootdoodoooo.com/xml/restructured.xml) a few small changes that should hopefully make all the difference.

Here's the different changes I've made and why:

Added the ?'s to the first item in the document to make it a proper XML prolog. It is now <?xml version="1.0"?> instead of <xml version="1.0" >. This is probably the biggest reason why your code could not load the XML file.


I've added a <Results> element to act as a document element that will contain ALL other elements. This is because a document having a document element is a "Well-formedness Constraint", and if a document is not well formed, it is not XML (which is another reason why your code might not have loaded the document).


I relplaced your <UserName> element with a <User> element that has the name of the user as an attribute and the <Test> and <Score> elements as its children. This is just because it's a slightly more sensible and intuitive structure and would make processing the data much easier.

If you can get your program to output in that format, then it should also be able to load it too. If it can load it, then we can start thinking about using XSLT to make it more readable for the therapist.

bella_11041988
05-12-2006, 09:19 PM
Hi, Stephen Philbin, thanks so much for your reply, appreciate.

I have changed the XML format (the ? symbol) to the correct one but the program still could not open the XML file. For the XML prolog and document issue, I still cant figure out how should I change in the program codes in order to obtain the format as stated in your post. Sorry.

Is it very difficult to do the XSLT?

Just asking, forgive me if I am wrong. Is it possible to copy the data in the XML file to a MFC dialog box? The data in the XML file is updated from time to time. I am just asking, I dont know whether it can be done or not. But, I just hope my problem can be solved using the simplest method as I am so stupid and I do not have enough knowledge due to my short experiences with programming (just about 2++ months) plus I am slow learner. Please forgive me. But, I promise I will try my best. I just need some advices at this very beginning.

Stephen Philbin
05-13-2006, 12:01 AM
Sorry, but I don't even know what an MFC dialog box is. I have no idea how you would change your visual C++ code to make files in the format I suggested rather than the one it makes now either. Like I said, you'd have to ask someone that knows about this visual C++ thing to get help with the visual C++ code. There should be plenty of people in the Code Guru forums (http://www.codeguru.com/forum/) that can help you with your visual C++ code.

The XSLT should be easy enough though. XSLT is done by using a source document (the document with all the data in it, like the example you uploaded and I altered a little) and an XSLT file. An XSLT file is just an XML file with instructions on how to restructure the data in the source document. You use the two documents together to make a new one (in this case, a more readable results set for the therapist). Again though, how you use the source XML file and the XSLT file depends on the language or software processing them (in this case visual C++), so you'd probably have to ask the good folks at the Code Guru forums about that too.

I can try to help you see errors in your XML input and output, but I can't help you with any visual C++ code, sorry.

bella_11041988
05-13-2006, 10:13 PM
Hi, Stephen Philbin, thank you for your explanation.

I will study the XSLT in details and see if I can understand it well. Thank you again.

bella_11041988
05-16-2006, 09:12 PM
HI, Stephen Philbin, thank you very much for your post, appreciate.

I have been reading for the XML tutorial for the past few days. I realized that I have two problems to be overcome.

1. My XML is not in a well-formed format. I would like to find out which section is wrong. Is there any web software to test or validate the XML? I tried the link below but I dont know why it cant work. Is there any other link to be used?
http://www.w3schools.com/dom/dom_validate.asp

2. From what I read, it specified that I should try to avoid the use of attributes if information feels like data, Use child elements if the information feels like data. In my case, many attributes are used and the information to be displayed are scoring data, means I should change the use of attributes to child elements? Do you mind to elaborate on how to change the use of attributes to child elements in the codes?

Stephen Philbin
05-17-2006, 01:59 AM
I know there are several pieces of software that you can be used to validate your XML, but I don't use any of them yet. I think you might be getting "valid" confused with "well formed" though (It's an easy mistake to make ;) ). In the XML recommendation there are two main constraint types: "Well-formedness" constraints and validation constraints. The distinction between them is important. The XML Recommendation states that an XML document must be well formed, but may not be valid. Here's a link to the actual definitions given in the Recommendation: http://www.w3.org/TR/2004/REC-xml-20040204/#dt-vc. Note that failing to comply with a well-formedness contraint is a fatal error and must cause the XML processor to cease processing, but if a processor chooses to validate a document where it is possible to validate it (ie. having a DTD to provide rules for the structure of the language and comparing the document to the rules given in the DTD), then it is a non-fatal error and the processor may continue processing. I think what you need to concern yourself with, is simply making sure the document is well-formed. I don't think (for now at least) that you need to bother validating it.

For simply checking that a document is well-formed, I just use my standard web browser of choice: Firefox (http://www.mozilla.com/firefox/). If you use firefox to view an XML document that is not well formed, it will present you with a rather ungraceful yellow screen pointing out the error, rather than the document you might have been expecting.

With regards to what should be elements and what should be attributes, I'd say do whatever you feel is best. That guide you quoted does make sense, but there are no real rules about how you structure your documents (which is kind of the point. You have the freedom to define everything yourself as your situation and requirements dictate.). The only reason I suggested a restructuring of your document was to make sure it met well-formedness constraints and to clean up that prolog so as not to confuse any other processors. The main things I keep in mind when deciding on structure is access through the DOM and Xpath, and how logical the structure is.

The reasons why I suggested using a <User> element with a name attribute was based on those ideas. I would simply consider it better structure to use the user element as the containing with the data tied to that user contained within it as child elements, rather than as sibling elements next to the user element. As for the data that goes inside the user element, well I'd just say structure it how you like. Just make sure it's consistent and makes sense.