XPath in Firefox 2.0: accessing attribute value
Here should go questions about transforming XML with XSLT and FOP.
-
- Posts: 4
- Joined: Fri Oct 27, 2006 11:09 pm
XPath in Firefox 2.0: accessing attribute value
XPath neophyte here...
I want to be able to drill down into a DOM object within Firefox and extract a particular element's attributes and their values.
The Javascript code starts out as follows:
All I know for now, is how to grab the particular attribute. But I haven't found any info on how to extract its value(s). Is there a [@id].getValue structure or equiv?
I want to be able to drill down into a DOM object within Firefox and extract a particular element's attributes and their values.
The Javascript code starts out as follows:
Code: Select all
// Selecting 'id' attribute of element 'project':
var xpathResult = document.evaluate("//project[@id]", domDoc, null, XPathResult.ANY_TYPE, null );
-
- Posts: 4
- Joined: Fri Oct 27, 2006 11:09 pm
Thanks for the reply.
Essentially I need to get a set of attributes with their name and values.
I found the following code at a Mozilla forum that takes an element (node) and return the attribute values (w/out the associated attribute names):
The above routine is the closest so far to what I'm after; just missing the associated attribute names.
I tried the following...
I'm sure there must be way to easily get the node name.
I'll revisit the Mozilla forum again and further explore the above code. I'm seeking the definition of XPathEvaluator. Docs are few and far between. Ditto with W3C docs.
Again, thanks for the info.
Any more ideas, suggestions are appreciated.
Essentially I need to get a set of attributes with their name and values.
I found the following code at a Mozilla forum that takes an element (node) and return the attribute values (w/out the associated attribute names):
Code: Select all
// Firefox routine.
// Evaluate an XPath expression aExpression against a given DOM node
// or Document object (aNode), returning the results as an array
// thanks wanderingstan at morethanwarm dot mail dot com for the
// initial work.
function evaluateXPath(aNode, aExpr) {
var xpe = new XPathEvaluator();
var nsResolver = xpe.createNSResolver(aNode.ownerDocument == null ?
aNode.documentElement : aNode.ownerDocument.documentElement);
var result = xpe.evaluate(aExpr, aNode, nsResolver, 0, null);
var found = [];
var res;
while (res = result.iterateNext())
found.push(res);
return found;
}
I tried the following...
I tried this approach and got the numeral '2'.PostPosted: Wed Nov 08, 2006 11:08 pm Post subject:
May be:
var xpathResult = document.evaluate("//project/@id", domDoc, null, XPathResult.ANY_TYPE, null );
And put XPathResult.STRING_TYPE.
I'm sure there must be way to easily get the node name.
I'll revisit the Mozilla forum again and further explore the above code. I'm seeking the definition of XPathEvaluator. Docs are few and far between. Ditto with W3C docs.
Again, thanks for the info.
Any more ideas, suggestions are appreciated.
-
- Posts: 6
- Joined: Thu Jan 18, 2007 10:11 pm
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service