|
Great article, i could start a new application very efficiently. I have a problem now. I'm trying to retrieve all the nodes <day> within a precise <month> tag, but using this instruction:
CXmlNodeListWrapper daysList(month.FindNodes("//day"));
i get all the days in the year (suppose the XML is organized in monthes and days..) instead of the days in the requiered month. Seems like the result is the same as using rootnode like this:
CXmlNodeListWrapper daysList(rootnode.FindNodes("//day"));
instead of just a month.
Do i miss anything?
Thanks, really helpful...
Mirko Ortensi
|
|
|
|
|
You should use a contitional statenemt like this:
Suppose you have this XML:
<root>
<january>
<day number="20">
<day number="15">
<day number="26">
<day number="11">
<day number="08">
<february>
<day number="20">
<day number="15">
<day number="26">
<day number="11">
<day number="08">
You can than select all of the days in February with this statement: "//February/Day"
And to select aspecific day: "//Febuary/Day[@Number=15]"
And so on...
Check out the XSL pattern reference here: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsdk/html/xmconpatterns.asp[^]
Creative minds - create creative creations!
|
|
|
|
|
Sorry the XML got formated...
The XML is as folows:
<Root>
<January>
<Day Number="12"></Day>
<Day Number="15"></Day>
<Day Number="16"></Day>
<Day Number="18"></Day>
<Day Number="25"></Day>
</January>
<Februaury>
<Day Number="05"></Day>
<Day Number="11"></Day>
<Day Number="16"></Day>
<Day Number="20"></Day>
<Day Number="26"></Day>
</Februaury>
</Root>
<span style="border-style: ridge; border-width: 1; background-color:#6699FF; font-weight:bold">
<font color="#FF3300">Creative minds - create creative creations!</font></span>
|
|
|
|
|
Also you could post your XML so I can write you the precise expression.
Creative minds - create creative creations!
|
|
|
|
|
Ok, i agree that having the XML structure you propose you can specify requested nodes like you say. My problem (it's not like days and monthes, but
it serves as a good example!) is related to the following XML:
<Root>
<Month>
<Day>1</Day>
<Day>2</Day>
<Day>3</Day>
<Day>4</Day>
<Day>5</Day>
</Month>
<Month>
<Day>6</Day>
<Day>7</Day>
<Day>8</Day>
<Day>9</Day>
<Day>10</Day>
</Month>
</Root>
I do not have the possibility to use attributes (i know it would make things easier, but no possibility), and doesn't matter which month is it, just consider as a set (it could really be <month>==<generic_set>).
So, i want to extract days separately from these sets, and i do like
this...:
// to get all monthes node
CXmlNodeListWrapper monthesList(Root.FindNodes("//Month"));
// parse each month
for (int j = 0; j < monthesList.Count(); j++){
// extract monthnode from list
CXmlNodeWrapper monthnode(monthesList.Node(j));
// get days under current Month
CXmlNodeListWrapper daysList(monthnode.FindNodes("//Day"));
// process daysList...
}
Well the problem i have is in the last instruction of the code:
instead of getting only the days under current Month (j==0:
1,2,3,4,5; j==1: 6,7,8,9,10) it gets all days (1,2,3,4,5,6,7,8,9,10)
for each month; so it seems like the instruction:
CXmlNodeListWrapper daysList(monthnode.FindNodes("//Day"));
acts like:
CXmlNodeListWrapper daysList(Root.FindNodes("//Day"));
getting the whole set of days in the sheet and not just the ones
under current month node.
I thank you for your attention, maybe it's an error of mine but i
cannot make headway!
Bye, Mirko
|
|
|
|
|
Hey! What about doing like this?
Instead of:
// get days under current Month
CXmlNodeListWrapper daysList(monthnode.FindNodes("//Day"));
i use this:
// get days under current Month
CXmlNodeListWrapper daysList(monthnode.FindNodes("//Month[j]/Day"));
so i get only the jth cube and so, only the days under it!!
Thank you very much for the link
http://msdn.microsoft.com/library/default.asp?url=/library/en-s/xmlsdk/html/xmconpatterns.asp
You saved me a lot of time, i'll rate your article; it's great tu put free code on the web, i do the same but i use gcc and i like multiplatform apps.
Mirko
|
|
|
|
|
Great article, i could start a new application very efficiently. I have a problem now. I'm trying to retrieve all the nodes <day> within a precise <month> tag, but using this instruction:
CXmlNodeListWrapper daysList(month.FindNodes("//day"));
i get all the days in the year (suppose the XML is organized in monthes and days..) instead of the days in the requiered month. Seems like i have used a rootnode like this:
CXmlNodeListWrapper daysList(rootnode.FindNodes("//day"));
instead of just a month.
Do i miss anything?
Thanks, really helpful...
Mirko Ortensi
|
|
|
|
|
Hello Alex,
Nice work, thanks for sharing.
--
Elias
|
|
|
|
|
But your miss is interface.
Where where very good class for xml (ce_xml - you can find it on this site)
Its interface like stl - well known, time-checked and very useful.
People too lasy for studying new interface.
|
|
|
|
|
Is there a specific reason you use MSMXL 3.0 instead of 4.0?
Just wondering, I changed the import to
#import <msxml4.dll> named_guids
and all seems to work fine.
Just wondering.
Thanks
|
|
|
|
|
No specific reason except that as for now ver 3 is more common than ver 4 , so that in most cases you don't even have to include MSXML redistributable in your package.
Creative minds - create creative creations!
|
|
|
|
|
Has anyone gotten this to compile using this compiler?
|
|
|
|
|
Fix for C++ 7.1:
There are apparently several IXMLDOMNodePtr etc. declarations wich are not prefixed with MSXML2::
prefix.
Find any of those: IXMLDOMNodePtr, IXMLDOMDocumentPtr, IXMLDOMNodeListPtr etc... and add a MSXML2:: prefix as: MSXML2::IXMLDOMNodePtr.
Also i'm posting a fix for this.
Creative minds - create creative creations!
|
|
|
|
|
Thanks that worked great.
|
|
|
|
|
alex,
when using the LoadXML method with a big file (800Kb) i get a stack overflow within MSXML and unfortunately i can't use the Load() method in this situation.
do you know of any such problems?
.dan.g.
AbstractSpoon Software
|
|
|
|
|
google has resolved this. there is a well known error in MSXML 3/4 when converting strings to BSTRs and vice versa. moreover someone has posted a fix on CP[^]!
.dan.g.
AbstractSpoon Software
|
|
|
|
|
|
As I understand from reading the summary it doesn't support XSL patterns which is IMHO is the main power of XML. Also the lack of dependancy on the DOM may be somewhat a disadvantage, since if the format changes the DOM architecture will still be back-compatible. And since my wrapper is dessigned for use with Windows and every windows since 98 comes with XML support built in, than I don't see a problem in DOM dependancy.
Creative minds - create creative creations!
|
|
|
|
|
|
hi alex
i've been looking for a msxml wrapper to replace my own custom xml parsing in ToDoList[^] and this looks like just the ticket.
if it all works out i'll add a suitable credit to ToDoList.
rgds
.dan.g.
AbstractSpoon Software
|
|
|
|
|
[Edit: link corrected]
Nice way of making the rather unwieldy DOM more convenient.
Sure you know the CMarkup-classes from www.firstobject.com[^]doing the same with a different approach?
What I am missing a little bit is a very small but running example on the article page, maybe right before the 'Reference' section. Your article seems to skip that a little.
Anyway, great article!
"We trained hard, but it seemed that every time we were beginning to form up into teams we would be reorganised. I was to learn later in life that we tend to meet any new situation by reorganising: and a wonderful method it can be for creating the illusion of progress, while producing confusion, inefficiency and demoralisation."
-- Caius Petronius, Roman Consul, 66 A.D.
|
|
|
|
|
First: You have mistyped the link, it's www.firstobject.com
Second: It's not free to use in a comericial product in opposite of the codeproject's consept where developers share their ideas for free use by others in any product comericial or not.
Third: I'll try to upload a sample to the article as long as it in Unedited section and I can change it by myself.
Creative minds - create creative creations!
|
|
|
|
|
I have corrected the link. You are right, for commercial products, CMarkup is not free. A very big plus for your product.
But their XML-Model called 'EDOM' is a very good method of reading and generating small to medium XML-Files. Your class - extending the MSDOM - can not hide the complexity of the underlying DOM completely.
Therefore I was asking for some example code to learn how to use your framework and how it makes using the quite unwieldy MSDOM easier (or even possible at all).
Thank you for extending your article!
"We trained hard, but it seemed that every time we were beginning to form up into teams we would be reorganised. I was to learn later in life that we tend to meet any new situation by reorganising: and a wonderful method it can be for creating the illusion of progress, while producing confusion, inefficiency and demoralisation."
-- Caius Petronius, Roman Consul, 66 A.D.
|
|
|
|
|
Also I've noticed that it doesn't support full search like XSL patterns, so this:
CXmlNodeListWrapper list(theNode.FindNodes("//Object[@Value < 8.6]"));
which returns all the "Object" elements with the attribute "Value" smaller than 8.6, is not possible...
Creative minds - create creative creations!
|
|
|
|
|
Sample added
Creative minds - create creative creations!
|
|
|
|