The problem is namespaces. XPath namespace prefixes are disconnected from
whatever namespaces may be declared in the original document. You need to
tell Jaxen what you mean by "svg" or "vars". Even what is a default
namespace in the original needs to be prefixed (and thus registered) in
XPaths.

This is coming up a lot at the moment. Should there be a FAQ somewhere?

Try the following:

Document doc = builder.build(new File(fileURItoSVG));
XPath xpath = new
JDOMXPath("//svg:metadata/vars:variableSets/vars:variableSet/vars:variables"
);

SimpleNamespaceContext nsContext = new SimpleNamespaceContext();
nsContext.addNamespace( "svg", "http://www.w3.org/2000/svg";);
nsContext.addNamespace( "vars", "http://ns.adobe.com/Variables/1.0/";);
xpath.setNamespaceContext(nsContext);

List variables = xpath.selectNodes(doc);

On a side note, it would be nice if it was simpler to set namespaces,
expecially since they are so common now-days. I'd prefer to simple be able
to go:

xpath.addNamespace( "svg", "http://www.w3.orb/2000/svg";);

than have to muck around with SimpleNamespaceContext.

David

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]]On Behalf Of Paul
Tomsic
Sent: Wednesday, 20 November 2002 10:10 AM
To: [EMAIL PROTECTED]
Subject: [Jaxen] xpath for an svg file, problems?


I'm having trouble getting the right XPath for
an SVG file.
What I'm trying to do is get to:

svg/metadata/variableSets/variableSet/variables/

and iterate thru the "variable" elements.

My code:
----
Document doc = builder.build(new File(fileURItoSVG));
XPath xpath = new
JDOMXPath("//metadata/variableSets/variableSet/variables");
List variables = xpath.selectNodes(doc);
----

but the variables.size() == 0

I've even tried:
svg:svg/svg:metadata/vars:variableSets/vars:variableSet/vars:variables
but with no success.
Any help greatly appreciated..

The beginning of the SVG:
------------------------------
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 10.0.3, SVG Export
Plug-In . SVG Version: 3.0.0 Build 77)  -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN"
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd";
[
        <!ENTITY ns_flows "http://ns.adobe.com/Flows/1.0/";>
        <!ENTITY ns_extend
"http://ns.adobe.com/Extensibility/1.0/";>
        <!ENTITY ns_ai
"http://ns.adobe.com/AdobeIllustrator/10.0/";>
        <!ENTITY ns_graphs "http://ns.adobe.com/Graphs/1.0/";>
        <!ENTITY ns_vars
"http://ns.adobe.com/Variables/1.0/";>
        <!ENTITY ns_imrep
"http://ns.adobe.com/ImageReplacement/1.0/";>
        <!ENTITY ns_sfw
"http://ns.adobe.com/SaveForWeb/1.0/";>
        <!ENTITY ns_custom
"http://ns.adobe.com/GenericCustomNamespace/1.0/";>
        <!ENTITY ns_adobe_xpath
"http://ns.adobe.com/XPath/1.0/";>
        <!ENTITY ns_svg "http://www.w3.org/2000/svg";>
        <!ENTITY ns_xlink "http://www.w3.org/1999/xlink";>
]>
<svg
         xmlns:x="&ns_extend;" xmlns:i="&ns_ai;"
xmlns:graph="&ns_graphs;" i:viewOrigin="-93.2031 0"
i:rulerOrigin="252 1098" i:pageBounds="-252 54 900
-1098" i:viewBoxInterpretation="asCropBox"
         xmlns="&ns_svg;" xmlns:xlink="&ns_xlink;"
xmlns:a="http://ns.adobe.com/AdobeSVGViewerExtensions/3.0/";
         width="648" height="1044" viewBox="-16.797 0 648
1044" enable-background="new -16.797 0 648 1044"
xml:space="preserve">
        <metadata>
                <variableSets
xmlns="http://ns.adobe.com/Variables/1.0/";>
                        <variableSet  varSetName="binding1" locked="none">
                                <variables>
                                        <variable  varName="subhead" 
trait="textcontent"
category="&ns_flows;"
docRef="id('XMLID_1_')"></variable>
                                        <variable  varName="Head" trait="textcontent"
category="&ns_flows;"
docRef="id('XMLID_2_')"></variable>
                                        <variable  varName="Image" trait="fileref"
category="&ns_vars;"
docRef="id('XMLID_3_')"></variable>
                                </variables>

------------------------------

thanks again...

Paul


__________________________________________________
Do you Yahoo!?
Yahoo! Web Hosting - Let the expert host your site
http://webhosting.yahoo.com


-------------------------------------------------------
This sf.net email is sponsored by: To learn the basics of securing
your web site with SSL, click here to get a FREE TRIAL of a Thawte
Server Certificate: http://www.gothawte.com/rd524.html
_______________________________________________
Jaxen-interest mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jaxen-interest



-------------------------------------------------------
This sf.net email is sponsored by: To learn the basics of securing 
your web site with SSL, click here to get a FREE TRIAL of a Thawte 
Server Certificate: http://www.gothawte.com/rd524.html
_______________________________________________
Jaxen-interest mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jaxen-interest

Reply via email to