|
alex,
i'm trying to build a fresh document from some data. i've instantiated a CXmlDocumentWrapper but when i call AsNode() on that object i get a NULL pointer returned.
i'm probably doing something daft, but can you help pls.
rgds
.dan.g.
AbstractSpoon Software
|
|
|
|
|
i discovered that the easiest way to initialize a document is to load it with some very simple xml,
eg doc.LoadXML("<a></a>");
and since xml must be contained within a single root item (i believe) this kinda makes sense.
.dan.g.
AbstractSpoon Software
|
|
|
|
|
Yep, that's exactly true.
You have to provide the root node.
Since when you instantiate a new document it doesn contain a single node. So you have to provide the root.
Creative minds - create creative creations!
|
|
|
|
|
alex,
i have some custom xml parsing code which i would like to replace with your wrappers but i have a one stumbling block at present: i need to build a xml document and then access the raw xml as text (specifically to encrypt it) before inserting that block as a CDATA element in another xml file. from my perusal of your source code i could not see a method which allows the raw xml to be grabbed straight from the document without having to save it to a temporary file and reload it as text. am i missing something?
rgds
.dan.g.
AbstractSpoon Software
|
|
|
|
|
There is a GetXML function for CXmlDocumentWrapper and CXmlNodeWrapper which returns a CString of the raw xml
Creative minds - create creative creations!
|
|
|
|
|
|
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!
|
|
|
|
|