Странности DOM парсера
От: dream_inspector  
Дата: 22.01.05 10:29
Оценка:
Имеется xml файл типа
      <output>        
        <writeto>file</writeto>
        <names>
            <services>services.bin</services>
            <methods>methods.bin</methods>
            <paths>paths.bin</paths>
            <query_strings>query_strings.bin</query_strings>
            <protocols>protocols.bin</protocols>
            <referrers>referrers.bin</referrers>
            <user_agents>user_agents.bin</user_agents>
            <cookies>cookies.bin</cookies>
            <content_types>content_types.bin</content_types>
            <set_cookies>set_cookies.bin</set_cookies>
        </names>
    </output>


имеется код
import org.w3c.dom.*;
import org.xml.sax.SAXException;
import javax.xml.parsers.*;
...........
...........
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    try {
      DocumentBuilder builder = factory.newDocumentBuilder();
      _xmlConfig = builder.parse(new File(resource.toString()));


при парсинге типа
      Node currentNameNode = namesNode.getFirstChild();      
      while (currentNameNode != null)
      {
          currentNameNode = currentNameNode.getNextSibling();
      }

namesNode это соответственно нод names в <output> наверху,
в currentNameNode поочередно садятся ноды с Value '\n\t\t\t'(пробелы и новая строка перед тем же <services>) и name-ом #text...
С получением value того же <services> делается ServiceNode.getFirstChild().getNodeValue, почтому что Value его самого null.. Вобщем впечатление что любой текст помещается в нод с именем #text и value-м этот текст. даже пробелы, \n и.т.д.
Вот такая вот ботва.. Может кто сталкивался..
JDK 1.4.2
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.