How can I parse text from date

<block> <date>27.08.2014</date> </block> 
  • Do you have this separately downloaded xml, or directly in the text of the html page? - KoVadim
  • I get txt file through $ .get () in which it is contained - Vlmake
  • not exactly easier to do json? not very kosher, but you can do something like this var date=$(data).find('date').text(); - zb '

1 answer 1

 <script type="text/javascript"> var w = "<block> <date>27.08.2014</date> </block>"; alert(w.substr(w.indexOf("<date>") + 6), w.indexOf("</date>") - w.indexOf("<date>") - 6)); <script> 
  • one
    For such an attempt to help - For an attempt + For having fun + And that 1 +. Not bad ... - Vlmake
  • What didn't you like? - S9ZAAAA
  • > What did not like? Well, probably because it is too naive implementation of something. and if you have xml with other nodes? With a different number of nodes, with different names, with a different nesting? Will you also write a bunch of indexOf for each new case? This is not serious - DreamChild
  • There are no telepaths here. No one knows what you have there. Where have you mentioned that this is XML? Then this: var w = "<block> <date> 08.27.2014 </ date> </ block>"; alert (w.match (/ <date> [0-9] {1,2} \. [0-9] {1,2} \. 20 [0-9] {2} <\ / date> /) [0] .substr (6, 10)); What is the question - that is the answer. - S9ZAAAA
  • In this case, you will not have problems with other nesting - S9ZAAAA