Back to index

lightning-sunbird  0.9+nobinonly
nsSOAPUtils.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 2001
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #include "nsSOAPUtils.h"
00039 #include "nsIDOMText.h"
00040 #include "nsISOAPEncoding.h"
00041 #include "nsIDOMNamedNodeMap.h"
00042 #include "nsIDOMAttr.h"
00043 #include "nsCOMPtr.h"
00044 #include "nsSOAPException.h"
00045 
00046 nsSOAPStrings::nsSOAPStrings()
00047   : NS_LITERAL_STRING_INIT(kSOAPEnvURI1, "http://schemas.xmlsoap.org/soap/envelope/")
00048   , NS_LITERAL_STRING_INIT(kSOAPEnvURI2, "http://www.w3.org/2001/09/soap-envelope")
00049   , NS_LITERAL_STRING_INIT(kSOAPEncURI, "http://www.w3.org/2001/09/soap-encoding")
00050   , NS_LITERAL_STRING_INIT(kSOAPEncURI11, "http://schemas.xmlsoap.org/soap/encoding/")
00051   , NS_LITERAL_STRING_INIT(kXSIURI, "http://www.w3.org/2001/XMLSchema-instance")
00052   , NS_LITERAL_STRING_INIT(kXSURI, "http://www.w3.org/2001/XMLSchema")
00053   , NS_LITERAL_STRING_INIT(kXSIURI1999, "http://www.w3.org/1999/XMLSchema-instance")
00054   , NS_LITERAL_STRING_INIT(kXSURI1999, "http://www.w3.org/1999/XMLSchema")
00055   , NS_LITERAL_STRING_INIT(kSOAPEnvPrefix, "env")
00056   , NS_LITERAL_STRING_INIT(kSOAPEncPrefix, "enc")
00057   , NS_LITERAL_STRING_INIT(kXSIPrefix, "xsi")
00058   , NS_LITERAL_STRING_INIT(kXSITypeAttribute, "type")
00059   , NS_LITERAL_STRING_INIT(kXSPrefix, "xs")
00060   , NS_LITERAL_STRING_INIT(kEncodingStyleAttribute, "encodingStyle")
00061   , NS_LITERAL_STRING_INIT(kActorAttribute, "actor")
00062   , NS_LITERAL_STRING_INIT(kMustUnderstandAttribute, "mustUnderstand")
00063   , NS_LITERAL_STRING_INIT(kEnvelopeTagName, "Envelope")
00064   , NS_LITERAL_STRING_INIT(kHeaderTagName, "Header")
00065   , NS_LITERAL_STRING_INIT(kBodyTagName, "Body")
00066   , NS_LITERAL_STRING_INIT(kFaultTagName, "Fault")
00067   , NS_LITERAL_STRING_INIT(kFaultCodeTagName, "faultcode")
00068   , NS_LITERAL_STRING_INIT(kFaultStringTagName, "faultstring")
00069   , NS_LITERAL_STRING_INIT(kFaultActorTagName, "faultactor")
00070   , NS_LITERAL_STRING_INIT(kFaultDetailTagName, "detail")
00071   , NS_LITERAL_STRING_INIT(kEncodingSeparator, "#")
00072   , NS_LITERAL_STRING_INIT(kQualifiedSeparator, ":")
00073   , NS_LITERAL_STRING_INIT(kXMLNamespaceNamespaceURI, "http://www.w3.org/2000/xmlns/")
00074   , NS_LITERAL_STRING_INIT(kXMLNamespaceURI, "http://www.w3.org/XML/1998/namespace")
00075   , NS_LITERAL_STRING_INIT(kXMLNamespacePrefix, "xmlns:")
00076   , NS_LITERAL_STRING_INIT(kXMLPrefix, "xml:")
00077   , NS_LITERAL_STRING_INIT(kTrue, "true")
00078   , NS_LITERAL_STRING_INIT(kTrueA, "1")
00079   , NS_LITERAL_STRING_INIT(kFalse, "false")
00080   , NS_LITERAL_STRING_INIT(kFalseA, "0")
00081   , NS_LITERAL_STRING_INIT(kVerifySourceHeader, "verifySource")
00082   , NS_LITERAL_STRING_INIT(kVerifySourceURI, "uri")
00083   , NS_LITERAL_STRING_INIT(kVerifySourceNamespaceURI, "urn:inet:www.mozilla.org:user-agent")
00084 
00085   , NS_LITERAL_STRING_INIT(kEmpty, "")
00086   , NS_LITERAL_STRING_INIT(kNull, "null")
00087   , NS_LITERAL_STRING_INIT(kNil, "nil")
00088   , NS_LITERAL_STRING_INIT(kSOAPArrayTypeAttribute, "arrayType")
00089   , NS_LITERAL_STRING_INIT(kSOAPArrayOffsetAttribute, "offset")
00090   , NS_LITERAL_STRING_INIT(kSOAPArrayPositionAttribute, "position")
00091   , NS_LITERAL_STRING_INIT(kAnyTypeSchemaType, "anyType")
00092   , NS_LITERAL_STRING_INIT(kAnySimpleTypeSchemaType, "anySimpleType")
00093   , NS_LITERAL_STRING_INIT(kArraySOAPType, "Array")
00094   , NS_LITERAL_STRING_INIT(kStructSOAPType, "Struct")
00095   , NS_LITERAL_STRING_INIT(kStringSchemaType, "string")
00096   , NS_LITERAL_STRING_INIT(kBooleanSchemaType, "boolean")
00097   , NS_LITERAL_STRING_INIT(kFloatSchemaType, "float")
00098   , NS_LITERAL_STRING_INIT(kDoubleSchemaType, "double")
00099   , NS_LITERAL_STRING_INIT(kLongSchemaType, "long")
00100   , NS_LITERAL_STRING_INIT(kIntSchemaType, "int")
00101   , NS_LITERAL_STRING_INIT(kShortSchemaType, "short")
00102   , NS_LITERAL_STRING_INIT(kByteSchemaType, "byte")
00103   , NS_LITERAL_STRING_INIT(kUnsignedLongSchemaType, "unsignedLong")
00104   , NS_LITERAL_STRING_INIT(kUnsignedIntSchemaType, "unsignedInt")
00105   , NS_LITERAL_STRING_INIT(kUnsignedShortSchemaType, "unsignedShort")
00106   , NS_LITERAL_STRING_INIT(kUnsignedByteSchemaType, "unsignedByte")
00107   , NS_LITERAL_STRING_INIT(kNormalizedStringSchemaType, "normalizedString")
00108   , NS_LITERAL_STRING_INIT(kTokenSchemaType, "token")
00109   , NS_LITERAL_STRING_INIT(kNameSchemaType, "Name")
00110   , NS_LITERAL_STRING_INIT(kNCNameSchemaType, "NCName")
00111   , NS_LITERAL_STRING_INIT(kDecimalSchemaType, "decimal")
00112   , NS_LITERAL_STRING_INIT(kIntegerSchemaType, "integer")
00113   , NS_LITERAL_STRING_INIT(kNonPositiveIntegerSchemaType, "nonPositiveInteger")
00114   , NS_LITERAL_STRING_INIT(kNonNegativeIntegerSchemaType, "nonNegativeInteger")
00115   , NS_LITERAL_STRING_INIT(kBase64BinarySchemaType, "base64Binary")
00116 {
00117   kSOAPEnvURI[0] = &kSOAPEnvURI1;
00118   kSOAPEnvURI[1] = &kSOAPEnvURI2;
00119 }
00120 
00121 void nsSOAPUtils::GetSpecificChildElement(nsISOAPEncoding * aEncoding,
00122                                           nsIDOMElement * aParent,
00123                                           const nsAString & aNamespace,
00124                                           const nsAString & aType,
00125                                           nsIDOMElement * *aElement)
00126 {
00127   nsCOMPtr<nsIDOMElement> sibling;
00128 
00129   *aElement = nsnull;
00130   GetFirstChildElement(aParent, getter_AddRefs(sibling));
00131   if (sibling) {
00132     GetSpecificSiblingElement(aEncoding, sibling, aNamespace, aType, aElement);
00133   }
00134 }
00135 
00136 void nsSOAPUtils::GetSpecificSiblingElement(nsISOAPEncoding * aEncoding,
00137                                             nsIDOMElement * aSibling,
00138                                             const nsAString & aNamespace,
00139                                             const nsAString & aType,
00140                                             nsIDOMElement * *aElement)
00141 {
00142   nsCOMPtr<nsIDOMElement> sibling;
00143 
00144   *aElement = nsnull;
00145   sibling = aSibling;
00146   do {
00147     nsAutoString name, namespaceURI;
00148     sibling->GetLocalName(name);
00149     if (name.Equals(aType)) {
00150       if (aEncoding) {
00151         nsAutoString temp;
00152         sibling->GetNamespaceURI(temp);
00153         aEncoding->GetInternalSchemaURI(temp, namespaceURI);
00154       }
00155       else {
00156         sibling->GetNamespaceURI(namespaceURI);
00157       }
00158       if (namespaceURI.Equals(aNamespace)) {
00159         *aElement = sibling;
00160         NS_ADDREF(*aElement);
00161         return;
00162       }
00163     }
00164     nsCOMPtr<nsIDOMElement> temp = sibling;
00165     GetNextSiblingElement(temp, getter_AddRefs(sibling));
00166   } while (sibling);
00167 }
00168 
00169 void nsSOAPUtils::GetFirstChildElement(nsIDOMElement * aParent,
00170                                        nsIDOMElement ** aElement)
00171 {
00172   nsCOMPtr<nsIDOMNode> child;
00173 
00174   *aElement = nsnull;
00175   aParent->GetFirstChild(getter_AddRefs(child));
00176   while (child) {
00177     PRUint16 type;
00178     child->GetNodeType(&type);
00179     if (nsIDOMNode::ELEMENT_NODE == type) {
00180       child->QueryInterface(NS_GET_IID(nsIDOMElement), (void **) aElement);
00181       break;
00182     }
00183     nsCOMPtr<nsIDOMNode> temp = child;
00184     GetNextSibling(temp, getter_AddRefs(child));
00185   }
00186 }
00187 
00188 void nsSOAPUtils::GetNextSiblingElement(nsIDOMElement * aStart,
00189                                         nsIDOMElement ** aElement)
00190 {
00191   nsCOMPtr<nsIDOMNode> sibling;
00192 
00193   *aElement = nsnull;
00194   GetNextSibling(aStart, getter_AddRefs(sibling));
00195   while (sibling) {
00196     PRUint16 type;
00197     sibling->GetNodeType(&type);
00198     if (nsIDOMNode::ELEMENT_NODE == type) {
00199       sibling->QueryInterface(NS_GET_IID(nsIDOMElement),
00200                               (void **) aElement);
00201       break;
00202     }
00203     nsCOMPtr<nsIDOMNode> temp = sibling;
00204     GetNextSibling(temp, getter_AddRefs(sibling));
00205   }
00206 }
00207 
00208 nsresult
00209     nsSOAPUtils::GetElementTextContent(nsIDOMElement * aElement,
00210                                        nsAString & aText)
00211 {
00212   aText.Truncate();
00213   nsCOMPtr<nsIDOMNode> child;
00214   nsAutoString rtext;
00215   aElement->GetFirstChild(getter_AddRefs(child));
00216   while (child) {
00217     PRUint16 type;
00218     child->GetNodeType(&type);
00219     if (nsIDOMNode::TEXT_NODE == type
00220         || nsIDOMNode::CDATA_SECTION_NODE == type) {
00221       nsCOMPtr<nsIDOMText> text = do_QueryInterface(child);
00222       nsAutoString data;
00223       text->GetData(data);
00224       rtext.Append(data);
00225     } else if (nsIDOMNode::ELEMENT_NODE == type) {
00226       return SOAP_EXCEPTION(NS_ERROR_ILLEGAL_VALUE,"SOAP_UNEXPECTED_ELEMENT", "Unable to retrieve simple content because a child element was present.");
00227     }
00228     nsCOMPtr<nsIDOMNode> temp = child;
00229     GetNextSibling(temp, getter_AddRefs(child));
00230   }
00231   aText.Assign(rtext);
00232   return NS_OK;
00233 }
00234 
00235 PRBool nsSOAPUtils::HasChildElements(nsIDOMElement * aElement)
00236 {
00237   nsCOMPtr<nsIDOMNode> child;
00238 
00239   aElement->GetFirstChild(getter_AddRefs(child));
00240   while (child) {
00241     PRUint16 type;
00242     child->GetNodeType(&type);
00243     if (nsIDOMNode::ELEMENT_NODE == type) {
00244       return PR_TRUE;
00245     }
00246     nsCOMPtr<nsIDOMNode> temp = child;
00247     GetNextSibling(temp, getter_AddRefs(child));
00248   }
00249 
00250   return PR_FALSE;
00251 }
00252 
00253 void nsSOAPUtils::GetNextSibling(nsIDOMNode * aSibling,
00254                                  nsIDOMNode ** aNext)
00255 {
00256   nsCOMPtr<nsIDOMNode> last;
00257   nsCOMPtr<nsIDOMNode> current;
00258   PRUint16 type;
00259 
00260   *aNext = nsnull;
00261   last = aSibling;
00262 
00263   last->GetNodeType(&type);
00264   if (nsIDOMNode::ENTITY_REFERENCE_NODE == type) {
00265     last->GetFirstChild(getter_AddRefs(current));
00266     if (!last) {
00267       last->GetNextSibling(getter_AddRefs(current));
00268     }
00269   } else {
00270     last->GetNextSibling(getter_AddRefs(current));
00271   }
00272   while (!current) {
00273     last->GetParentNode(getter_AddRefs(current));
00274     current->GetNodeType(&type);
00275     if (nsIDOMNode::ENTITY_REFERENCE_NODE == type) {
00276       last = current;
00277       last->GetNextSibling(getter_AddRefs(current));
00278     } else {
00279       current = nsnull;
00280       break;
00281     }
00282   }
00283   *aNext = current;
00284   NS_IF_ADDREF(*aNext);
00285 }
00286 
00287 nsresult
00288     nsSOAPUtils::GetNamespaceURI(nsISOAPEncoding * aEncoding,
00289                                  nsIDOMElement * aScope,
00290                                  const nsAString & aQName,
00291                                  nsAString & aURI)
00292 {
00293   aURI.Truncate();
00294   PRInt32 i = aQName.FindChar(':');
00295   if (i < 0) {
00296     return NS_OK;
00297   }
00298   nsAutoString prefix;
00299   prefix = Substring(aQName, 0, i);
00300 
00301   nsAutoString result;
00302   if (prefix.Equals(gSOAPStrings->kXMLPrefix)) {
00303     result.Assign(gSOAPStrings->kXMLNamespaceURI);
00304   }
00305   else {
00306 
00307     nsresult rc;
00308     nsCOMPtr<nsIDOMNode> current = aScope;
00309     nsCOMPtr<nsIDOMNamedNodeMap> attrs;
00310     nsCOMPtr<nsIDOMNode> temp;
00311     nsAutoString value;
00312     while (current) {
00313       rc = current->GetAttributes(getter_AddRefs(attrs));
00314       if (NS_FAILED(rc))
00315         return rc;
00316       if (attrs) {
00317         rc = attrs->GetNamedItemNS(gSOAPStrings->kXMLNamespaceNamespaceURI, prefix,
00318                                    getter_AddRefs(temp));
00319         if (NS_FAILED(rc))
00320           return rc;
00321         if (temp) {
00322           rc = temp->GetNodeValue(result);
00323           if (NS_FAILED(rc))
00324             return rc;
00325           break;
00326         }
00327       }
00328       rc = current->GetParentNode(getter_AddRefs(temp));
00329       if (NS_FAILED(rc))
00330         return rc;
00331       current = temp;
00332     }
00333     if (!current)
00334       return SOAP_EXCEPTION(NS_ERROR_FAILURE,"SOAP_NAMESPACE", "Unable to resolve prefix in attribute value to namespace URI");
00335   }
00336   if (aEncoding) {
00337     return aEncoding->GetInternalSchemaURI(result,aURI);
00338   }
00339   aURI.Assign(result);
00340   return NS_OK;
00341 }
00342 
00343 nsresult
00344     nsSOAPUtils::GetLocalName(const nsAString & aQName,
00345                               nsAString & aLocalName)
00346 {
00347   PRInt32 i = aQName.FindChar(':');
00348   if (i < 0)
00349     aLocalName = aQName;
00350   else
00351     aLocalName = Substring(aQName, i+1, aQName.Length() - (i+1));
00352   return NS_OK;
00353 }
00354 
00355 nsresult
00356     nsSOAPUtils::MakeNamespacePrefix(nsISOAPEncoding * aEncoding,
00357                                      nsIDOMElement * aScope,
00358                                      const nsAString & aURI,
00359                                      nsAString & aPrefix)
00360 {
00361 //  This may change for level 3 serialization, so be sure to gut this
00362 //  and call the standardized level 3 method when it is available.
00363   nsAutoString externalURI;
00364   if (aEncoding) {
00365     nsresult rc = aEncoding->GetExternalSchemaURI(aURI,externalURI);
00366     if (NS_FAILED(rc))
00367       return rc;
00368   }
00369   else {
00370     externalURI.Assign(aURI);
00371   }
00372   aPrefix.Truncate();
00373   if (externalURI.IsEmpty())
00374     return NS_OK;
00375   if (externalURI.Equals(gSOAPStrings->kXMLNamespaceURI)) {
00376     aPrefix.Assign(gSOAPStrings->kXMLPrefix);
00377     return NS_OK;
00378   }
00379   nsCOMPtr<nsIDOMNode> current = aScope;
00380   nsCOMPtr<nsIDOMNamedNodeMap> attrs;
00381   nsCOMPtr<nsIDOMNode> temp;
00382   nsAutoString tstr;
00383   nsresult rc;
00384   PRUint32 maxns = 0;                //  Keep track of max generated NS
00385   for (;;) {
00386     rc = current->GetAttributes(getter_AddRefs(attrs));
00387     if (NS_FAILED(rc))
00388       return rc;
00389     if (attrs) {
00390       PRUint32 i;
00391       PRUint32 count;
00392       rc = attrs->GetLength(&count);
00393       if (NS_FAILED(rc))
00394         return PR_FALSE;
00395       for (i = 0;i < count;i++) {
00396         attrs->Item(i, getter_AddRefs(temp));
00397         if (!temp)
00398           break;
00399         temp->GetNamespaceURI(tstr);
00400         if (!tstr.Equals(gSOAPStrings->kXMLNamespaceNamespaceURI))
00401           continue;
00402         temp->GetNodeValue(tstr);
00403         if (tstr.Equals(externalURI)) {
00404           nsAutoString prefix;
00405           rc = temp->GetLocalName(prefix);
00406           if (NS_FAILED(rc))
00407             return rc;
00408           nsCOMPtr<nsIDOMNode> check = aScope;
00409           PRBool hasDecl;
00410           nsCOMPtr<nsIDOMElement> echeck;
00411           while (check != current) {        // Make sure prefix is not overridden
00412             echeck = do_QueryInterface(check);
00413             if (echeck) {
00414               rc = echeck->
00415                   HasAttributeNS(gSOAPStrings->kXMLNamespaceNamespaceURI, prefix,
00416                                  &hasDecl);
00417               if (NS_FAILED(rc))
00418                 return rc;
00419               if (hasDecl)
00420                 break;
00421               echeck->GetParentNode(getter_AddRefs(check));
00422             }
00423           }
00424           if (check == current) {
00425             aPrefix.Assign(prefix);
00426             return NS_OK;
00427           }
00428         }
00429         rc = temp->GetLocalName(tstr);
00430         if (NS_FAILED(rc))
00431           return rc;
00432         else {                        //  Decode the generated namespace into a number
00433           nsReadingIterator < PRUnichar > i1;
00434           nsReadingIterator < PRUnichar > i2;
00435           tstr.BeginReading(i1);
00436           tstr.EndReading(i2);
00437           if (i1 == i2 || *i1 != 'n')
00438             continue;
00439           i1++;
00440           if (i1 == i2 || *i1 != 's')
00441             continue;
00442           i1++;
00443           PRUint32 n = 0;
00444           while (i1 != i2) {
00445             PRUnichar c = *i1;
00446             i1++;
00447             if (c < '0' || c > '9') {
00448               n = 0;
00449               break;
00450             }
00451             n = n * 10 + (c - '0');
00452           }
00453           if (n > maxns)
00454             maxns = n;
00455         }
00456       }
00457     }
00458     current->GetParentNode(getter_AddRefs(temp));
00459     if (temp)
00460       current = temp;
00461     else
00462       break;
00463   }
00464 // Create a unique prefix...
00465   PRUint32 len = 3;
00466   PRUint32 c = maxns + 1;
00467   while (c >= 10) {
00468     c = c / 10;
00469     len++;
00470   }
00471 // Set the length and write it backwards since that's the easiest way..
00472   aPrefix.SetLength(len);
00473   nsWritingIterator < PRUnichar > i2;
00474   aPrefix.EndWriting(i2);
00475   c = maxns + 1;
00476   while (c > 0) {
00477     PRUint32 r = c % 10;
00478     c = c / 10;
00479     i2--;
00480     *i2 = (PRUnichar) (r + '0');
00481   }
00482   i2--;
00483   *i2 = 's';
00484   i2--;
00485   *i2 = 'n';
00486 
00487   // Declare the fabricated prefix
00488   if (aScope) {
00489     tstr.Assign(gSOAPStrings->kXMLNamespacePrefix);
00490     tstr.Append(aPrefix);
00491     rc = aScope->SetAttributeNS(gSOAPStrings->kXMLNamespaceNamespaceURI,
00492                                 tstr, externalURI);
00493   }
00494   return NS_OK;
00495 }
00496 
00505 PRBool nsSOAPUtils::GetAttribute(nsISOAPEncoding *aEncoding,
00506                                   nsIDOMElement * aElement,
00507                                   const nsAString & aNamespaceURI,
00508                                   const nsAString & aLocalName,
00509                                   nsAString & aValue)
00510 {
00511   nsAutoString value;
00512   nsresult rc = aEncoding->GetExternalSchemaURI(aNamespaceURI, value);  //  Try most-likely result first.
00513   if (NS_FAILED(rc))
00514     return PR_FALSE;
00515   {
00516     nsCOMPtr<nsIDOMAttr> attr;
00517     rc = aElement->GetAttributeNodeNS(value, aLocalName, getter_AddRefs(attr));
00518     if (NS_FAILED(rc))
00519       return PR_FALSE;
00520     if (attr) {
00521       rc = attr->GetNodeValue(aValue);
00522       if (NS_FAILED(rc))
00523         return PR_FALSE;
00524       return PR_TRUE;
00525     }
00526   }
00527   nsCOMPtr<nsIDOMNamedNodeMap> attrs;
00528   rc = aElement->GetAttributes(getter_AddRefs(attrs));
00529   if (NS_FAILED(rc))
00530     return PR_FALSE;
00531   PRUint32 count;
00532   rc = attrs->GetLength(&count);
00533   if (NS_FAILED(rc))
00534     return PR_FALSE;
00535   PRUint32 i;
00536   for (i = 0; i < count; i++) {
00537     nsCOMPtr<nsIDOMNode> attrnode;
00538     rc = attrs->Item(i, getter_AddRefs(attrnode));
00539     if (NS_FAILED(rc))
00540       return PR_FALSE;
00541     rc = attrnode->GetLocalName(value);
00542     if (NS_FAILED(rc))
00543       return PR_FALSE;
00544     if (!aLocalName.Equals(value))
00545       continue;
00546     rc = attrnode->GetNamespaceURI(value);
00547     if (NS_FAILED(rc))
00548       return PR_FALSE;
00549     nsAutoString internal;
00550     rc = aEncoding->GetInternalSchemaURI(value, internal);
00551     if (NS_FAILED(rc))
00552       return PR_FALSE;
00553     if (!aNamespaceURI.Equals(internal))
00554       continue;
00555     rc = attrnode->GetNodeValue(aValue);
00556     if (NS_FAILED(rc))
00557       return PR_FALSE;
00558     return PR_TRUE;
00559   }
00560   SetAStringToNull(aValue);
00561   return PR_FALSE;
00562 }