/    Sign up×
Community /Pin to ProfileBookmark

I have a site where I retrive information (articles submitted by the current user) and allow the user to edit them. The article information is in XML format. The code works in FF, but only gives me nulls in IE (like the elements don’t exist, but since it works in FF I know the document I am refering to is correct URL (yes, I do show the URL that am retrieving data from.)
(sorry for posting a large snitbit)

var _AC_tmp_XMLDoc;
function XMLParser(doc, fcn, fcn2){

_AC_tmp_XMLDoc = “”;
if (document.implementation && document.implementation.createDocument){
_AC_tmp_XMLDoc = document.implementation.createDocument(“”, “”, null);
_AC_tmp_XMLDoc.onload = fcn;
}
else if (window.ActiveXObject)
{
_AC_tmp_XMLDoc = new ActiveXObject(“Microsoft.XMLDOM”);
_AC_tmp_XMLDoc.onreadystatechange = fcn2;
}
else
{
alert(‘Your browser can’t handle this script’);
return;
}
_AC_tmp_XMLDoc.load(doc);

this.getTextArrayForTag = function(tag){
var arry = new Array();
var x = xmlDoc.getElementsByTagName(tag);
var tmplnt = x.length;
for(var i = 0; i < tmplnt; i++){
this.getElementTextNS(tag, i);
}
return arry;
}

this.toString = function(){
return “XMLParser:JK:2”
}

this.getReadyState = function(){
return _AC_tmp_XMLDoc.readyState;
}

this.getElementsByTagName = function(tag){
prefix = “”;
var result = “”;
if (prefix && isIE) {
// IE/Windows way of handling namespaces
result = _AC_tmp_XMLDoc.getElementsByTagName(prefix + “:” + tag);
} else {
// the namespace versions of this method
// (getElementsByTagNameNS()) operate
// differently in Safari and Mozilla, but both
// return value with just local name, provided
// there aren’t conflicts with non-namespace element
// names
result = _
AC_tmp_XMLDoc.getElementsByTagName(tag);
}
//alert(result);
return result;
}

// retrieve text of an XML document element, including
// elements using namespaces
this.getElementTextNS = function (local, index) {
var result = this.getElementsByTagName(local)[index];
if (result) {
// get text, accounting for possible
// whitespace (carriage return) text nodes
if (result.childNodes.length > 1) {
return result.childNodes[1].nodeValue;
} else {
return result.firstChild.nodeValue;
}
} else {
return “n/a”;
}
}

}

Another problem. I have to have the variable _AC_tmp_XMLDoc global because I need to reference its readyState bc IE has no onload rutiune (that I am aware of). I would love to have it encapsulated inside my Object, but cannot do this as of now. It seems that if an object creates an event, the object cannot be referenced by the function it calls to handle the event (I’ve seen this in multible places).

Any help would be gladly appriciated.

BTW: the doc is good XML.

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@jimktrainsauthorAug 17.2005 — As an addendum:

I think it is the MS parser not liking my XML. I tried an XMLHTTPRequest (thiking it may use a different parser?). When I alert the responseText, it is the correct document.

The XML is:

<?xml version="1.0" encoding="UTF-8"?>

<article>

<title>Polluting Plants</title>

<stitle>Polluting Plants</stitle>

<author>fname lname</author>

<aemail>[email protected]</aemail>

<date>030616</date>

<wcurl>NULL</wcurl>

<wctext>&lt;i&gt;The Case for Mars&lt;/i&gt; - Robert Zubrin</wctext>

<type>Article</type>

<type>Terraforming</type>

<type>Biology</type>

<type>Engineering</type>

<txt>&lt;p&gt;Many folks on this website, and elsewhere have suggested raising the temperature of Mars by intentionally producing greenhouse gasses by way of factories set up on mars for such a purpose.</txt>

(the txt tags is repeated for every paragraph)

</article>

I think this is (simple, yet) valid XML? Could it be that the MS parser doesn't like something about what I am doing?

I'm about to cry; I've spent 24 hours in 6 blocks over 2 days getting this to work (and it does). Why can't it just work like Mozilla?

Please help
Copy linkTweet thisAlerts:
@A1ien51Aug 17.2005 — Play with this:
<i>
</i>var reqXML;
function LoadXMLDoc(url){
if (window.XMLHttpRequest){
reqXML = new XMLHttpRequest();
}
else if(window.ActiveXObject){
reqXML = new ActiveXObject("Microsoft.XMLHTTP");
}

if(reqXML){
reqXML.open("POST", url, true);
reqXML.onreadystatechange = BuildXMLResults;
reqXML.send(null);
}
else{
alert("Your browser does not support Ajax");
}
}

function BuildXMLResults(){
if(reqXML.readyState == 4){
if(reqXML.status == 200){
var strText = reqXML.responseText;
var strXML = reqXML.responseXML.documentElement;
}
else{
alert("There was a problem retrieving the XML data:n" + reqXML.statusText);
}
}
}


Eric
Copy linkTweet thisAlerts:
@jimktrainsauthorAug 17.2005 — Thanks for your reply.

I made strText and strXML global. When I alert them I get the correct document text (strText) in both browsers, but when I alert strXML I get (as expected) "[Object Element]" in FF, but I get null in IE.

Is my XML not what IE wants?

Is there a way to retrieve any parse errors from the parser?

Again, thanks for any help.
Copy linkTweet thisAlerts:
@jimktrainsauthorAug 18.2005 — I'm sorry to have asked a question that you really couldn't solve. I profusly appologize for wasting your time.

My freind found the .parseError in IE (I couldn't find it...). My XML doc was encoded wrong. That didn't even dawn on me because FF parsed it. I guess here's a trip to Bugzzila (and a 2hr stay[so complecated...]).
×

Success!

Help @jimktrains spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...