I wrote half of it -- the half concerning XPath -- here. The other half will discuss the most efficient means to read/write XML to/from DOM objects.
By the way, I really hate adding my code samples to the Dev/Extensions/Example Code section. I'd rather add them to the new Category/Example Code section, but for the life of me, I can't figure it out. I'm sort of a n00bie when it comes to wiki editing. Any advice? Ideally, I'd like to move that article and some others I've written (as well as the one I will write re: read/write DOM objects) to the Category/Example Code section.
Do you think it makes sense to write a class encapsulating all of this? A class which easily allows you to read XML into a DOM, write XML into a DOM, query a DOM using XPath or regex, transform a DOM into another DOM by applying an XSL template, etc... (more features as I think of them, using other XML apis...)
Edit: asqueella replied before I could hit "submit" !
best way to read/write XML?
-
- Posts: 3
- Joined: May 4th, 2006, 12:29 pm
Hello,
When I tried to cretae the XpathEvaluator as :
var xpe = new XPathEvaluator();
I get the following error on Mozilla Thunderbird :
Erreur : [Exception... "Object cannot be created in this context" code: "9" nsresult: "0x80530009 (NS_ERROR_DOM_NOT_SUPPORTED_ERR)" location: "chrome://automailsorter/content/autoMailSorterUserFolder.js Line: 82"]
Fichier source : chrome://automailsorter/content/autoMailSorterUserFolder.js
Ligne : 82
I don't understand why...
When I tried to cretae the XpathEvaluator as :
var xpe = new XPathEvaluator();
I get the following error on Mozilla Thunderbird :
Erreur : [Exception... "Object cannot be created in this context" code: "9" nsresult: "0x80530009 (NS_ERROR_DOM_NOT_SUPPORTED_ERR)" location: "chrome://automailsorter/content/autoMailSorterUserFolder.js Line: 82"]
Fichier source : chrome://automailsorter/content/autoMailSorterUserFolder.js
Ligne : 82
I don't understand why...
-
- Posts: 6
- Joined: June 19th, 2006, 3:14 am
Bad resolution!!!
Hi grimholtz,
been trying the posted code, as is, with no fundamental changes and getting an error on the NSResolver method in the evaluate function (renamed to DSW_evaluate):
THE ERROR
THE CULPRIT
THE FILE
I'm trying to write a toolbar widget that will switch the domain but retain the page name and I want to use an XML file to contain the different domains, but I am a n00b to AJAX and Firefox dev.
I am using Firefox 1.5.0.4 and it reads the file in OK as far as I can tell, but fails on the resolver.
Can anyone help?
been trying the posted code, as is, with no fundamental changes and getting an error on the NSResolver method in the evaluate function (renamed to DSW_evaluate):
THE ERROR
Code: Select all
Error: uncaught exception: [Exception... "Component returned failure code: 0x80070057 (NS_ERROR_ILLEGAL_VALUE) [nsIDOMXPathEvaluator.createNSResolver]" nsresult: "0x80070057 (NS_ERROR_ILLEGAL_VALUE)" location: "JS frame :: chrome://domainswitchwidget/content/domainswitchwidget.js :: DSW_evaluate :: line 61" data: no]
THE CULPRIT
Code: Select all
function DSW_ReloadXML()
{
var fileContents = readFile("environments.xml");
var results = DSW_evaluate(fileContents, "//dept/@name");
}
function DSW_evaluate(aXmlDoc, aXpath) {
var xpe = new XPathEvaluator();
var found = new Array();
var result = xpe.evaluate(aXpath, aXmlDoc, xpe.createNSResolver(aXmlDoc.documentElement), 0, null);
while (res = result.iterateNext())
found.push(res);
return found;
}
THE FILE
Code: Select all
<?xml version="1.0"?>
<environments>
<dept name="Perfume">
<box name="Desk 9" ip="192.168.0.32"/>
</dept>
</environments>
I'm trying to write a toolbar widget that will switch the domain but retain the page name and I want to use an XML file to contain the different domains, but I am a n00b to AJAX and Firefox dev.
I am using Firefox 1.5.0.4 and it reads the file in OK as far as I can tell, but fails on the resolver.
Can anyone help?