0

Hello i am programming in Java and..

I have an xml file and I am thinking of using xpath to grab every character between the elements in the code below: I was wondering how would this be done in xpath? I do not want to parse it because between the tags are lots of other tags and attributes and text..

<book>
 <book element 1>
  ........
 </book element 1>

 <book element 2>
  <DATA>.............
  ..............
  ...........
  </DATA>
 </book element 2>
</book>
dronyx
  • 1
  • possible duplicate of [Java XML parsing: taking inner XML using SAX](http://stackoverflow.com/questions/5028613/java-xml-parsing-taking-inner-xml-using-sax) – Marc B Jul 20 '11 at 15:28
  • I don't want to parse it as I want to keep every single character between and . Including all the tags, attributes, spacing..etc – dronyx Jul 20 '11 at 15:30
  • This is just a restatement of your previous question: http://stackoverflow.com/questions/6755475 – parsifal Jul 20 '11 at 15:36
  • query for `//DATA`, then extract nodeValue from each found node? – Marc B Jul 20 '11 at 15:37
  • i like the sound of that MarcB. How do you say extract nodeValue from //data? i'm not familiar with xpath – dronyx Jul 20 '11 at 15:45
  • @Marc: according to http://java.sun.com/webservices/reference/tutorials/jaxp/html/dom.html#gesxh, the nodeValue() of an element returns null. I assume you're talking about this DOM Node API? – LarsH Jul 20 '11 at 17:48
  • this must be possible to do..it doesn't sound hard when you think..I have a file with text in it..and i want to retrieve everything between two tags.. – dronyx Jul 20 '11 at 20:28

2 Answers2

0

So, you want to parse the document to the extent that you locate the DATA start and end tags, but you then want access to the unparsed text between these tags. I can't think of an approach that will give you that. You can always reconstitute the markup from the parsed content, of course, but that's not what you asked for.

So, if it's not possible to do what you are trying to do, that might be a good indication that you are tackling your problem the wrong way. To advise you on that, we need to know what your problem is.

Michael Kay
  • 156,231
  • 11
  • 92
  • 164
-1

Can't you just use <xsl:copy-of select="books/books"/>?

H.Muster
  • 9,297
  • 1
  • 35
  • 46
Treemonkey
  • 2,133
  • 11
  • 24