 |
|
|
 |
|
 |
Thanks for the refreshing C in a world of VB, C#, and .NET. I have a good fundamental knowledge of using the SAX reader and even rolling my own XML writer based on SAX events. I always knew that the MXXMLWriter class was a better way to go and I appreciate your article.
|
|
|
|
 |
|
 |
I've read the MSDN help on ISaxContentHandler::startElement. I cannot get the first two parameters to write out (uri, and local name). It appears only using the qualified name will create an XML that writes out properly. In the MSDN, it says:
"The startElement event allows up to three of the following name components for each element:
* Name space URI
* Local name
* QName
Any or all of these name components may be specified, depending on the values of the "http://xml.org/sax/features/namespaces" and the "http://xml.org/sax/features/namespace-prefixes" features. The name space URI and local name are required when the "http://xml.org/sax/features/namespaces" feature is True (the default). These values are optional when this feature is set to False. Note that neither the URI nor local name value can be specified on its own. Both values are required if either is used.
The QName is required when the "http://xml.org/sax/features/namespaces-prefixes feature" is True and is optional when this feature is False (the default)."
But I can find no where on how to set the "features" mentioned. How can I make it so that the uri and local names are used so that I do not require a qualified name to write out correctly?
|
|
|
|
 |
|
 |
Those "features" seem to be properties of the SAX Reader, the getProperty and putProperty methods may be of help here. The MSDN documentation was unclear but I found mention of the ones you mention in other SAX documentation. I hope these are supported by Microsoft's parser.
|
|
|
|
 |
|
 |
Yeah, I found those, but that doesn't really help when I'm writing, right? When I'm writing, I can't seem to get the URI and local name to work/write out, only the qname as in your example.
|
|
|
|
 |
|
 |
How about calling startPrefixMapping?
Just a shot in the dark. Unfortunately to this day I still have not completely gotten this namespace stuff. I have been able to avoid using it in the XML data that I deal with (guess no WS-* and other fun stuff for me ).
|
|
|
|
 |
|
 |
Felix Cho wrote: I have been able to avoid using it in the XML data that I deal with
That is the route I'm taking right now. I have hooks that if someone smarter than myself can figure out how to use the URI and local name fields, they are more than welcome, but for what I'm doing now, I just use the qname field. Unfortunately, the reader portion was written by someone else and looks like it was mainly concerned with local name (but not URI,ironically...so I don't know what they were really doing/thinking). My solution is just to ignore the URI/localname and only use the qname, inserting the xmlns attribute as a straight up attribute (which I assumed would happen automatically if i figured out how to use the URI correctly). We'll see how this goes. I've posted in the MSXML forums about this issue, so if I hear anything I'll post here as well.
|
|
|
|
 |
|
 |
Hello Sir,
I am writing an application where it requries XML data from windows Clipboard,i could able to gather the text by using
char *buffer = (char *)GetClipboardData(CF_TEXT);
but when i copied any XML data into the clipboard, and called the function, i couldn't able to get the contents present in the Clipboard(XML data).
Could you please help me in this regard.
Thanks in advance.
From Gopinath MV
|
|
|
|
 |
|
 |
CoCreateInstance is giving an error
ERROR:debug information corrupt;recompile
I have included msxml2.h and necessary settings.
|
|
|
|
 |
|
 |
Never seen that error. Looks like something really weird. CoCreateInstance() does not depend on msxml2.h. It's standard COM. Make sure you have the correct libs installed.
It may be helpful if you list your development environment:
- OS
- IDE (VS6, VS.NET 2002, or?)
- Do you have the latest Platform SDK installed?
A bit of your code may help also.
|
|
|
|
 |
|
 |
OS:WinXP
IDE:(VS6,VC++)
If latest platform SDK installed means MSXML parser then it is MSXML3.
Settings:
In Project/settings/link(tab) Object/library modules:"msxml2.lib"
If "Generate debug info" is unchecked error does not appear.
In Tools/Options/Directories(tab) given path for include and lib files.
1st&4th parameters fo CoCreateInstance() ie.
CLSID_DOMDocument & IID_IXMLDOMDocument does need to #include
|
|
|
|
 |
|
 |
For the record, msxml2.lib and msxml.h are not MSXML3. They are the "default" MSXML version 2 that ships with Windows 2000 and XP. For MSXML3, one way of "including it" is to use the #import directive on msxml3.dll.
Without getting more info it is hard to determine what is happening. Since you have a workaround by unchecking the "Generate debug info", we shouldn't persue this further in a forum setting.
You seem to have quite a bit to learn doing normal COM in addition to mixing that COM stuff with MFC and tree view controls. I suggest you do some further reading on all that to get yourself up to speed.
Try creating some normal COM object (just grab a beginner's COM book and copy the first sample) and see if the error is still there.
Good luck.
|
|
|
|
 |
|
 |
Hi!
First of all thanks to Felix Cho.
I am using document view architechture having 2 views
1)source view and
2)tree view.
Now if i edit values in xml file using tree view,i need to update the source view.For that i need to take some data structure in document class.So that i can use UpdateAllViews().
Which data structure(class) to use and how?
Also can we traverse DOM tree and reflect it in document class.
(Programming in MFC)
|
|
|
|
 |
|
 |
Most "xml editor" I have seen use a tree view with a listview/grid on the right. That way you can display the attributes within the node as well. If you are just using the tree view you have to think about how to display everything so users can edit them.
By "source view", do you mean the actualy XML source? If you allow them to edit the source view directly it will be very tricky to synchronize from that side. Think about it, it may be more trouble than it is worth.
There is no out-of-box data structure for you to use that automatically handles tree like structure. Since each case is different you really have to think about how it's used. You can use the container classes to help you achieve that. A CList is a collection of nodes, those can point to their own container too.
Looks like you need more help than just rendering XML, you have more things to learn before you can attempt this. Go read some more articles under this XML section to help you out. There are helper classes and wrapper to help you deal with the DOM stuff. And there are other articles to help you understand the various collection classes.
We can't do everything for you here in these forums. We can only give you pointers. You still have to do most of the work.
|
|
|
|
 |
|
 |
Hi there!
I am working on a project(XML Editor) in MFC ,
in which i need to give a tree view of the xml file.
Do i need to use xml parser to do so.
Please answer quickly.
|
|
|
|
 |
|
 |
If the XML file is not too big, the best way is to use the DOM parser because DOM is a tree-like structure already.
If you have to use the SAX parser then you will have to maintain some sort of state machine when you are handling the events.
|
|
|
|
 |
|
 |
Hi
I found this article, very useful and thanks for your service.
I have got a question.
If I want to write the xml data to a file using SAX, instead of writing to a string using , what is that I n to do?
Thanks in adavce
|
|
|
|
 |
|
 |
You can write the string to a file (remember BSTRs are wchar's on NT/XP), or output the data to an IStream. For the latter you will need to refer to the documentation.
|
|
|
|
 |
|
 |
In MFC, there is a function call
BeginWaitCursor( )
You could use it when you want your app. in wait cursor mode.
EndCursor() to terminate
|
|
|
|
 |
|
 |
Hi, I download this program on my machine, and it compiles successfully. But when I try to execute this program, an error message pop up "This program has performed an illegal operation and will be shut down."
Could you tell me what should I do to get this program running? By the way, the msxml3.dll is in the folder "c:\windows\system\" of my computer.
Thank you in advance!
|
|
|
|
 |
|
 |
arthuryu wrote:
an error message pop up "This program has performed an illegal operation and will be shut down."
Could you tell me what should I do to get this program running? By the way, the msxml3.dll is in the folder "c:\windows\system\" of my computer.
Without further information I can't really give any insights. From what you have stated here I am suspecting that you are running on a Win9x machine and you may be running a unicode build?
If you can debug the program and tell me where it crashes I can probably give more details.
Thanks.
|
|
|
|
 |
|
 |
That was just what I was looking for to help me to get started.
And here's one more question:
How to make it use UTF-8 encoding. I read that encoding is ignored if output is to string. What I really need is to ouput to binary file and use UTF-8.
Any ideas how to do that?
Thank in advance
|
|
|
|
 |
|
 |
I have the same problem before.You can use a IStream,and direct the output to the stream
|
|
|
|
 |
|
 |
Thank you Felix,
I tried to do the same based on your (and markg's) example.
Everything is fine untill I changed
CoInitialize(NULL);
to
CoInitializeEx(NULL, COINIT_MULTITHREADED);
(The last init requires _WIN32_DCOM defined in VC6)
Objects are (Co)Created successfully, but never return pointers to supported interfaces.
I never met this problem while playing with the DOM part of msxml3.dll.
Do you now if there any specifics with SAX that cause problems in multithreaded contexts.
Thanks,
Alex
|
|
|
|
 |
|
 |
Just did a quick scan of the registry, the MXXML Writer 3.0 (CLSID: 3d813dfe-6c91-4a4e-8f41-04346a841d9c) is apartment threaded while most of the other objects in the msxml3.dll are both.
May be that's why? I stopped my search once I hit that object so may be there are more that cause the problem?
BTW, where is markg's sample?
|
|
|
|
 |