Click here to Skip to main content
15,887,175 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have the output as inner HTML but i am getting the text among tags alltogether, i want then to be line by line .
XML
<span style="font-weight: bold">Test topic newTest topic new<task xmlns=""><taskbody cid="2B7Jv8"><steps id="GUID-7C705467-7088-4738-8E69-288AAC3371AD"><step cid="12wGt3"><cmd>I am a new topic again.<substeps id="GUID-C5017927-15CF-4AC1-A632-11A42AC1BFAE"><substep cid="MZhWE"><cmd>I must look how to cause a topic.<info cid="2E1jok"><fig cid="mCpaB"><note id="GUID-43DCE40A-2AE4-412B-8AE1-805AF28A50F9">Please do not over write the content.<step cid="Tihet"><cmd>Hello second step</span>


Current output

Test topic newTest topic newI am a new picture againI must look how to cause a picturePlease do not over write the picture Hello second step



Expected result

Test topic new
Test topic new
I am a new picture again
I must look how to cause a picture
Please do not over write the picture
Hello second step


can anyone help me to get the expected result by spliting using regex or anyway will be helpful

What I have tried:

var original = document.getElementById("response1id").nextElementSibling.innerHTML.split(???);


i have tried seeing the stackoverflow suggestion but they are spliting the known tags, i my case i cant guess what the tags are.
Posted
Updated 16-Aug-21 20:57pm
v2
Comments
[no name] 16-Aug-21 16:17pm    
There's no "meta data" on which to split "Test topic new". Also, your "periods" seemed to have disappeared; which should have served as a signal for a line break.
PIEBALDconsult 16-Aug-21 20:01pm    
https://blog.codinghorror.com/parsing-html-the-cthulhu-way/
PIEBALDconsult 16-Aug-21 20:04pm    
Were it XML I'd use an XmlDocument and XPath to iterate all the Text nodes.
riya reddy 20-Aug-21 3:37am    
I am taking input as xml and xslt and the transformed html output is the one which i need to split tag by tag
PIEBALDconsult 20-Aug-21 9:28am    
Then output ought to be XHTML so it should be consumable as XML.

1 solution

$(function(){
var text = $.trim($('#content').text()),
word = text.split(' ');
alert(word[1])
});
 
Share this answer
 
Comments
Richard Deeming 17-Aug-21 4:22am    
Aside from the word "split", what does this have to do with the question?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900