Subject: DOMParser in mfcembed - msg#00011
List: mozilla.devel.dom
Hi, guys,
I insert the following code to a function BOOL
CMfcEmbedApp::InitializeProfiles() to parse a xml string.
But the do_CreateInstance failed.
Can somebody tell me why?
Thank you very much.
This is just a test code for dom parser.
My final target is to let mfcembed load an xml without rendering and my code
parse the xml and load other xhtml files indicated by href in the startup
xml.
/* my code begins */
char szXML[] = "<?xml version=\"1.0\" encoding=\"utf-8\"?><startup>
<wallgarden> <loadinfo href=\"a.htm\"/> </wallgarden></startup>";
nsresult rv;
nsCOMPtr<nsIDOMParser> pDOMParser;
nsCOMPtr<nsIDOMDocument> pDOMDocument;
pDOMParser = do_CreateInstance( NS_DOMPARSER_CONTRACTID,
&rv );
if (NS_SUCCEEDED( rv )) {
nsString str; str.AssignWithConversion(szXML);
rv = pDOMParser->ParseFromString(str.get(),"text/xml",
getter_AddRefs( pDOMDocument ) );
if (NS_SUCCEEDED( rv )) {
printf( "DOM parse string successful\n");
}
else {
printf( "DOM parse of NOT successful\n");
}
}
else {
printf( "do_CreateInstance of DOMParser failed for - %08X\n", rv );
}
/* my code ends */
Was this page helpful?
Thread at a glance:
Previous Message by Date:
click to view message preview
instanceof/prototype problem with objects created in different frames
I am currently exploring prototype based inheritance when scripting with
frames and using objects created in one frame in script in another
frame. Mozilla (tested with 1.7.3) shows an odd behaviour when applying
the instanceof operator on an object created in one frame and a
constructor function created in another frame, it yields instanceof as
true but when you check for a property defined on the prototype then the
property is not found with the in operator.
A test case using Date objects is here:
http://home.arcor.de/martin.honnen/javascript/200412/test2004120601.html
another test case that deals with DOM object (document object in that
case) is here:
http://home.arcor.de/martin.honnen/javascript/200412/test2004120502.html
From my understanding it is correct that an object created in one frame
doesn't have the properties defined on the prototype of a constructor
function created in another frame as that prototype doesn't sit in the
prototype chain of the object but then I wonder why Mozilla gives
instanceof as true for that object and that constructor function. It
seems like a bug to me but before I file one I thought I would ask here
for opinions.
IE 6 and Opera 7.50 give the same results as Mozilla (for the first test
case) for the 'in' operator checks but then (in my view consistently)
yield false for the instanceof check for the object created in one frame
and the constructor function created in another frame where Mozilla
yields true.
In case the above is not detailed enough to understand what I am after I
will explain a bit more now: with JavaScript you can add
properties/methods to the prototype of constructor functions e.g.
Date.prototype.foo = function () { ... };
and then objects created with that constructor function 'inherit' those
properties/methods as that prototype object sits in the prototype chain
an object is hooked up to.
In JavaScript 1.5 (or other ECMAScript edition 3 implementations) there
is also the instanceof operator e.g.
object instanceof functionObject
that returns true or false depending on (in my understanding) the
prototype of the functionObject sits in the prototype chain of the
object. Thus if you are only looking at one window/frame then if you have
var date = new Date()
then
date instanceof Date
yields true and
'foo' in date
is also true.
Now enter frames and scripting between frames and you have different
global objects and different constructor functions like Date in each
frame so consequently if you create a Date object in one frame e.g.
var date = new Date()
and then check instanceof on the constructor in another frame it should
yield false e.g.
date instanceof parent.frames.frameName.Date
but in Mozilla it doesn't, I get true.
Why is that? In particular as a check of properties with the in operator
yields false. I think that is inconsistent, if
object instanceof functionObject
is true and a property/method
functionObject.prototype.foo
exists (the test case checks that using hasOwnProperty) the
'foo' in object
needs to be true too.
So what do you think, should I file a bug on Mozilla yielding true on
objectCreatedInOneFrame instanceof functionCreatedInOtherFrame
or do you have an explanation for that?
--
Martin Honnen
http://JavaScript.FAQTs.com/
Next Message by Date:
click to view message preview
MY SISTER NAKED IN SHOWER
http://sister.sister.com
sister_1.scr
Description: Binary data
Previous Message by Thread:
click to view message preview
instanceof/prototype problem with objects created in different frames
I am currently exploring prototype based inheritance when scripting with
frames and using objects created in one frame in script in another
frame. Mozilla (tested with 1.7.3) shows an odd behaviour when applying
the instanceof operator on an object created in one frame and a
constructor function created in another frame, it yields instanceof as
true but when you check for a property defined on the prototype then the
property is not found with the in operator.
A test case using Date objects is here:
http://home.arcor.de/martin.honnen/javascript/200412/test2004120601.html
another test case that deals with DOM object (document object in that
case) is here:
http://home.arcor.de/martin.honnen/javascript/200412/test2004120502.html
From my understanding it is correct that an object created in one frame
doesn't have the properties defined on the prototype of a constructor
function created in another frame as that prototype doesn't sit in the
prototype chain of the object but then I wonder why Mozilla gives
instanceof as true for that object and that constructor function. It
seems like a bug to me but before I file one I thought I would ask here
for opinions.
IE 6 and Opera 7.50 give the same results as Mozilla (for the first test
case) for the 'in' operator checks but then (in my view consistently)
yield false for the instanceof check for the object created in one frame
and the constructor function created in another frame where Mozilla
yields true.
In case the above is not detailed enough to understand what I am after I
will explain a bit more now: with JavaScript you can add
properties/methods to the prototype of constructor functions e.g.
Date.prototype.foo = function () { ... };
and then objects created with that constructor function 'inherit' those
properties/methods as that prototype object sits in the prototype chain
an object is hooked up to.
In JavaScript 1.5 (or other ECMAScript edition 3 implementations) there
is also the instanceof operator e.g.
object instanceof functionObject
that returns true or false depending on (in my understanding) the
prototype of the functionObject sits in the prototype chain of the
object. Thus if you are only looking at one window/frame then if you have
var date = new Date()
then
date instanceof Date
yields true and
'foo' in date
is also true.
Now enter frames and scripting between frames and you have different
global objects and different constructor functions like Date in each
frame so consequently if you create a Date object in one frame e.g.
var date = new Date()
and then check instanceof on the constructor in another frame it should
yield false e.g.
date instanceof parent.frames.frameName.Date
but in Mozilla it doesn't, I get true.
Why is that? In particular as a check of properties with the in operator
yields false. I think that is inconsistent, if
object instanceof functionObject
is true and a property/method
functionObject.prototype.foo
exists (the test case checks that using hasOwnProperty) the
'foo' in object
needs to be true too.
So what do you think, should I file a bug on Mozilla yielding true on
objectCreatedInOneFrame instanceof functionCreatedInOtherFrame
or do you have an explanation for that?
--
Martin Honnen
http://JavaScript.FAQTs.com/
Next Message by Thread:
click to view message preview
Re: DOMParser in mfcembed
I tried to create other instance from xmlextras extension like
"@mozilla.org/xmlextras/xmlserializer;1". It succeed.
Don't know what's going on.
Can somebody help?
"Chris Du" <cheng_du2000@xxxxxxxxx> wrote in message
news:cp5giv$j021@xxxxxxxxxxxxxxxxxxxxxx
> Hi, guys,
>
> I insert the following code to a function BOOL
> CMfcEmbedApp::InitializeProfiles() to parse a xml string.
> But the do_CreateInstance failed.
> Can somebody tell me why?
> Thank you very much.
>
> This is just a test code for dom parser.
> My final target is to let mfcembed load an xml without rendering and my
> code parse the xml and load other xhtml files indicated by href in the
> startup xml.
>
> /* my code begins */
> char szXML[] = "<?xml version=\"1.0\" encoding=\"utf-8\"?><startup>
> <wallgarden> <loadinfo href=\"a.htm\"/> </wallgarden></startup>";
> nsresult rv;
> nsCOMPtr<nsIDOMParser> pDOMParser;
> nsCOMPtr<nsIDOMDocument> pDOMDocument;
> pDOMParser = do_CreateInstance( NS_DOMPARSER_CONTRACTID,
> &rv );
>
> if (NS_SUCCEEDED( rv )) {
> nsString str; str.AssignWithConversion(szXML);
> rv = pDOMParser->ParseFromString(str.get(),"text/xml",
> getter_AddRefs( pDOMDocument ) );
>
> if (NS_SUCCEEDED( rv )) {
> printf( "DOM parse string successful\n");
> }
> else {
> printf( "DOM parse of NOT successful\n");
> }
> }
> else {
> printf( "do_CreateInstance of DOMParser failed for - %08X\n", rv );
> }
>
> /* my code ends */
>