Patches item #1218625, was opened at 2005-06-10 21:58
Message generated for change (Tracker Item Submitted) made by Item Submitter
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: Open
Resolution: None
Priority: 5
Submitted By: larry hamel (larham)
Assigned to: Nobody/Anonymous (nobody)
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>
> 


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

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


-------------------------------------------------------
This SF.Net email is sponsored by: NEC IT Guy Games.  How far can you shotput
a projector? How fast can you ride your desk chair down the office luge track?
If you want to score the big prize, get to know the little guy.  
Play to win an NEC 61" plasma display: http://www.necitguy.com/?r=20
_______________________________________________
dom4j-dev mailing list
dom4j-dev@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/dom4j-dev

Reply via email to