Patches item #1218625, was opened at 2005-06-11 06:58
Message generated for change (Comment added) made by maartenc
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=316035&aid=1218625&group_id=16035

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: None
Group: None
>Status: Closed
>Resolution: Fixed
Priority: 5
Submitted By: larry hamel (larham)
>Assigned to: Maarten Coene (maartenc)
Summary: faq for XPath using default namespace

Initial Comment:
hi,

Attached is faq.fml with a new entry for XPath using default namespace (faq.fml 
modified from CVS 10 June 2005).  I hope that you will consider adding this 
since there are several questions about this issue already.

Below is the diff.

thanks,

larry hamel

------------------
Index: faq.fml
===================================================================
RCS file: /cvsroot/dom4j/dom4j/xdocs/faq.fml,v
retrieving revision 1.6
diff -r1.6 faq.fml
621a622,674
>   <faq id="xpath-with-default-namespace">
>     <question>XPath fails: how can I work around a default 
> namespace?</question>
>     <answer>
> 
>       <p>Say you have an XML document that declares a default namespace, as 
> in the example below,
>         where the first 'xmlns' definition that has no colon after 'xmlns', 
> thus making it the default:
>       </p>
> 
> <pre><![CDATA[
> <?xml version="1.0" encoding="UTF-8"?>
> <assessmentItem xmlns="http://www.imsglobal.org/xsd/imsqti_v2p0";
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
> xsi:schemaLocation="http://www.imsglobal.org/xsd/imsqti_v2p0 imsqti_v2p0.xsd"
> identifier="choiceMultiple" title="Composition of Water" adaptive="false" 
> timeDependent="false">
>     <itemBody>
>         <choiceInteraction responseIdentifier="blah" shuffle="true" 
> maxChoices="0">
>             <prompt>Which of the following elements are components of 
> water?</prompt>
> 
>             <simpleChoice identifier="H" fixed="false">Hydrogen</simpleChoice>
>             <simpleChoice identifier="O" fixed="false">Oxygen</simpleChoice>
>             <simpleChoice identifier="N" fixed="false">Nitrogen</simpleChoice>
>             <simpleChoice identifier="Cl" 
> fixed="false">Chlorine</simpleChoice>
> 
>         </choiceInteraction>
>     </itemBody>
> </assessmentItem>
>  ]]>
> </pre>
>         <p>Because XPath does not assume a default namespace (as per the 
> specification--no fault of dom4j),
>             the following query will fail:
>         </p>
> <pre>
>     List choiceList = root.selectNodes("//simpleChoice");
> </pre>
> 
>         <p>
>         For the example above, you could use the entire
>             namespace identifier in front of each XPath element. Instead, you 
> can define
>             a prefix for the default namespace in code, and make it part of 
> the XPath query:
>         </p>
> <pre>
>     HashMap map = new HashMap();
>     map.put("qti",
>             "http://www.imsglobal.org/xsd/imsqti_v2p0";);
> 
>     XPath xpath = DocumentHelper.createXPath("//qti:simpleChoice");
>     xpath.setNamespaceURIs(map);
>     List choiceList = xpath.selectNodes(root);
> </pre>
> 
>     </answer>
>   </faq>
> 


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

>Comment By: Maarten Coene (maartenc)
Date: 2005-07-22 12:18

Message:
Logged In: YES 
user_id=178745

Fixed in the DOM4J_1_X_BRANCH:

Checking in faq.fml;
/cvsroot/dom4j/dom4j/xdocs/faq.fml,v  <--  faq.fml
new revision: 1.6.2.1; previous revision: 1.6
done

thanks!
Maarten

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

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=316035&aid=1218625&group_id=16035


-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
dom4j-dev mailing list
dom4j-dev@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/dom4j-dev

Reply via email to