开发者

How to add string content in xml nodes(empty node/append to existing content) using XPath Query

I have the following xml structure already available with the childnodes as title, desc, symp, diag, treat addinfo etc. I want to check that whether addinfo contains any thing and also append some string to it like "This is additional info". There are many disease title I need to check the addifo tag according to disease title-title tag.

<chapter>
  <disease typ开发者_如何学Ce="Name">
    <title>Name</title>
    <desc>--------------</desc>
    <symp>--------------</symptoms>
    <diag>-------------</diagnosis>
    <treat>-------------</treatment>
    <addinfo></addinfo>
  </disease>
</chapter

>

I am using XPath query for searching the content of the tags according to the disease name. Thanks


XPath can only retrieve information from your document, it cannot modify it.

XQuery can produce a modified copy of your document, but it's not particularly easy, because you need to explicitly copy all the parts that you don't want to change.

XSLT is a better bet for producing a modified copy of the document; or XQuery Update Facility if you prefer.


You can use an XPath like this to see if addinfo is empty or not: //addinfo[not(node())]

UPDATE:

Ok, now am totally lost as to what you want. It sounds like a really straightforward problem. You would create some sort of getText() method that given an XML node, gets the text associated with it (if any or returns null or empty string). Then you would do a traversal of all the diseases and for each disease, perform your logic: if( string.isNullOrEmpty(getText(disease, "addinfo")) ) { // do something } -- if you want to check whether addinfo is empty or add stuff to it etc..

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜