开发者

How to clear bodycontent of a custom tag?

How do I clear the body content placed inside a Custom tag?

<abc:myTag display="true">

   <b> Clear this content </b>  

<abc:myTag />

Based on the display="true" boolean flag in my tag handler, I want to clea开发者_如何学JAVAr out the content "Clear this content". I tried:

         if(display){
            getBodyContent();
            } else
            try {
                getBodyContent().clear();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

but its throwing a null pointer exception


If you have a reference to the custom element you can do

for (Node child; (child = myCustomElement.getFirstChild()) != null;) {
  myCustomElement.removeChild(child);
}

If you need to get a reference to the custom element you can do something like

Element myCustomElement = myDocument.getElementsByTagNameNS(namespaceForAbc, "myTag");

or if you aren't using XML namespaces, you can do

Element myCustomElement = myDocument.getElementsByTagName("abc:myTag");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜