/****************************************************************************
 * Copyright/Copyleft: 
 * 
 * For this source the LGPL Lesser General Public License, 
 * published by the Free Software Foundation is valid.
 * It means:
 * 1) You can use this source without any restriction for any desired purpose.
 * 2) You can redistribute copies of this source to everybody.
 * 3) Every user of this source, also the user of redistribute copies 
 *    with or without payment, must accept this license for further using.
 * 4) But the LPGL ist not appropriate for a whole software product,
 *    if this source is only a part of them. It means, the user 
 *    must publish this part of source,
 *    but don't need to publish the whole source of the own product.
 * 5) You can study and modify (improve) this source 
 *    for own using or for redistribution, but you have to license the
 *    modified sources likewise under this LGPL Lesser General Public License.
 *    You mustn't delete this Copyright/Copyleft inscription in this source file.    
 *
 * @author www.vishia.de/Java
 * @version 2006-06-15  (year-month-day)
 * list of changes: 
 * 2006-05-00 JcHartmut: creation
 *
 ****************************************************************************/
package org.vishia.xml;

import net.sf.saxon.om.Axis;
import net.sf.saxon.om.AxisIterator;
import net.sf.saxon.om.Item;
import net.sf.saxon.om.NodeInfo;
import net.sf.saxon.type.Type;


/**Not ready yet, it is a trying to use the saxons path */
public class WikiFormat
{
  void process(NodeInfo xmlTree)
  { processNodeAndChilds(xmlTree);
  
    
    AxisIterator iterChild = xmlTree.iterateAxis(Axis.CHILD);
    Item itemChild = iterChild.current();
    @SuppressWarnings("unused")
    NodeInfo child = (NodeInfo)(itemChild); 
    //processNodesAtLevel(child);
    
  }
  
  void processNodesAtLevel(NodeInfo node)
  {
    processNodeAndChilds(node);
    AxisIterator iter; 
    iter = node.iterateAxis(Axis.FOLLOWING_SIBLING);
    do
    {
      Item item = iter.current();
      if(item instanceof NodeInfo)
      { node = (NodeInfo)(item);
        processNodeAndChilds(node);
      }
    } while(iter.moveNext());
    
  }
  
  
  void processNodeAndChilds(NodeInfo node)
  {
    int type = node.getNodeKind();
    switch(type)
    { case Type.ELEMENT:
      {
      
      } break;
      case Type.ATTRIBUTE:
      {
      
      } break;
        
    }
    String name = node.getDisplayName();
    String value = node.getStringValue();
    System.out.println(name + ":" + value);
    AxisIterator iterChild = node.iterateAxis(Axis.CHILD);
    Item itemChild = iterChild.current();
    if(itemChild instanceof NodeInfo)
    { NodeInfo child = (NodeInfo)(itemChild); 
      processNodesAtLevel(child);
    }  
    
  }
  
}
