How to merge Two xml tags
Hi i am new to XML i dint write any xml for my application, i want to merge two xml tags or giving link to one tag to another together(ie) data of one tag should be copied to another tag. for example
<tag1>data</tag1> <tag2>tag1 data</tag2>.
Here i want to share the data of tag1 in tag2. for this i have given
<开发者_JAVA技巧tag1 xml:id='tag1'>some data</tag1>
<tag2 xlink:href='#tag1' />
but the data are not linked together. if any other knows how to link xml tags together pls guide me
It's not at all difficult to do this say in XSLT; but there's not enough information here to tell you exactly how.
If you want to become proficient in XML and XSLT it helps to learn the right terminology. The things you are linking are not tags, they are elements. You have two elements, each of which has two tags: a start tag and an end tag.
Let's break it down, you need to:
read in the xml string
combine the data (value) from 2 tags into 1
output the new xml string
I recommend using a library, such as Xerces, though I haven't tried it myself.
Your problem is too poorly specified to give a proper answer.
However, if I had a problem like this, I'd probably create an XSL transform that recognized matched the cases where there was sharing, and transformed it into the desired form.
Warning: doing this in a general fashion could be very expensive in CPU resources. You are probably better off trying to get the original application to generate the XML in the desired format.
精彩评论