Here's code if you want it. Lemme know if I botched something.
/**
*Sets the namespace of the element to the given namespace
*/
public static void setNamespace(Element elem, Namespace ns){
elem.setQName( QName.get( elem.getName(), ns,
elem.getQualifiedName() ) );
}
/**
*Recursively removes the namespace of the element and all its
children: sets to Namespace.NO_NAMESPACE
*/
public static void removeNamespaces(Element elem){
setNamespaces(elem, Namespace.NO_NAMESPACE);
}
/**
*Recursively removes the namespace of the list and all its
children: sets to Namespace.NO_NAMESPACE
*/
public static void removeNamespaces(List l){
setNamespaces(l, Namespace.NO_NAMESPACE);
}
/**
*Recursively sets the namespace of the element and all its children.
*/
public static void setNamespaces(Element elem, Namespace ns){
setNamespace(elem, ns);
setNamespaces(elem.content(), ns);
}
/**
*Recursively sets the namespace of the List and all children if the
current namespace is match
*/
public static void setNamespaces(List l, Namespace ns){
Node n = null;
for(int i=0; i<l.size(); i++){
n = (Node)l.get(i);
if(n.getNodeType() == Node.ATTRIBUTE_NODE) ( (Attribute)n
).setNamespace(ns);
if(n.getNodeType() == Node.ELEMENT_NODE) setNamespaces(
(Element)n, ns );
}
}
Naveen Murthy wrote:
>
> hello Edwin,
>
> in the older versions of dom4j,
>
> we could use -->
> Doc.getRootElement().addAttribute("xmlns","http://www.w3.org/2001/06/grammar");
>
> and this would make "http://www.w3.org/2001/06/grammar" as the DEFAULT
> namespace for
> the whole doc (whichwould apply to allthe child elemnts of the root.)
>
> Wondering if same can be somehow done for dom4j.1.6.
>
>
> Herez an example which i have in my appln ( frm older dom4j).
> all child elements are in the namespace
> ="http://vmw.test.com/eventNotification/v1/xsd"
> . (this is verified by schemavalidation, xsd says that "WorkAGR" shud
> be in
> "http://vmw.test.com/eventNotification/v1/xsd" namespace & it does pass
> schemavalidation;)
>
> <eventNotificationMsg
> xmlns="http://vmw.test.com/eventNotification/v1/xsd">
> <WorkAGR>
> <TimeSent>0620916202344</TimeSent>
> <BasePriority>10</BasePriority><Center>MODELCNTCTR</Center>
> <CustomerName>MISS Jane</CustomerName>
> </WorkAGR>
> </eventNotificationMsg>
>
> ------------------------------------------------------------------------
>
> -------------------------------------------------------------------------
> Take Surveys. Earn Cash. Influence the Future of IT
> Join SourceForge.net's Techsay panel and you'll get the chance to share your
> opinions on IT & business topics through brief surveys -- and earn cash
> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
> ------------------------------------------------------------------------
>
> _______________________________________________
> dom4j-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/dom4j-user
>
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
dom4j-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/dom4j-user