JTree with XML Content

Hi Friends,
I am trying to create a JTree whose data will come from a XML Document. Whenever the tree is refreshed (There is a JPopupMenu on the tree which allows the user to call refresh), the tree must update itself with the underlying XML document. If there is any change in the xml doc, it must be reflected in the tree. However, the tree must not collapse when the refresh is called. For example if I have a tree like this:-
+ Root
    |
    ------ Child #1
    |            |
    |            -------- A
    |            |
    |            -------- B
    |
    +------ Child #2
    |
    ------- Child #3
                |
                -------- AAA
                |
                -------- BBBThe XML Document for the above tree structure would be:-
<?xml version="1.0" encoding="UTF-8"?>
<Root>Root
      <Child> Child #1
            <SubChild>A</SubChild>
            <SubChild>B</SubChild>
      </Child>
      <Child> Child #2
            <SubChild>AA</SubChild>
            <SubChild>BB</SubChild>
      </Child>
      <Child> Child #3
            <SubChild>AAA</SubChild>
            <SubChild>BBB</SubChild>
      </Child>
</Root>Now if i add another node (CCC) in Child #3 (by adding another Subchild element in the XML document), and click refresh on the tree, the tree should look like:-
+ Root
    |
    ------ Child #1
    |            |
    |            -------- A
    |            |
    |            -------- B
    |
    +------ Child #2
    |
    ------- Child #3
                |
                -------- AAA
                |
                -------- BBB
                |
                -------- CCCHowever, if i am trying to reload the tree model, after reading the XML file, the whole tree collapses.
Can anyone please help me out with this problem?
Thanx a lot in advance,
~Debopam

* XMLNode.java
* Created on December 18, 2004, 4:25 PM
package debopam.utils.xml;
import java.util.Enumeration;
import java.util.NoSuchElementException;
import java.util.Vector;
import javax.swing.tree.MutableTreeNode;
import javax.swing.tree.TreeNode;
import org.jdom.Element;
* @author Debopam Ghoshal
public class XMLNode implements MutableTreeNode
    private Element nodeElement;
    private XMLNode parent;
    /** optional user object */
    transient protected Object     userObject;
    /** true if the node is able to have children */
    protected boolean allowsChildren;
    /** array of children, may be null if this node has no children */
    protected Vector children;
     * An enumeration that is always empty. This is used when an enumeration
     * of a leaf node's children is requested.
    static public final Enumeration<TreeNode> EMPTY_ENUMERATION
            = new Enumeration<TreeNode>()
        public boolean hasMoreElements()
        { return false; }
        public TreeNode nextElement()
            throw new NoSuchElementException("No more elements");
    /** Creates a new instance of XMLNode */
    public XMLNode(Element nodeElement, boolean allowsChildren)
        this.nodeElement = nodeElement;
        this.allowsChildren = allowsChildren;
    public XMLNode(String nodeName, boolean allowsChildren)
        nodeElement = new Element(nodeName);
        this.allowsChildren = allowsChildren;
     * Creates and returns a forward-order enumeration of this node's
     * children.  Modifying this node's child array invalidates any child
     * enumerations created before the modification.
     * @return     an Enumeration of this node's children
    public java.util.Enumeration children()
        if(children == null)
            return EMPTY_ENUMERATION;
        else
            return children.elements();
     * Returns true if this node is allowed to have children.
     * @return     true if this node allows children, else false
    public boolean getAllowsChildren()
        return allowsChildren;
     * Determines whether or not this node is allowed to have children.
     * If <code>allows</code> is false, all of this node's children are
     * removed.
     * <p>
     * Note: By default, a node allows children.
     * @param     allows     true if this node is allowed to have children
    public void setAllowsChildren(boolean allows)
        if (allows != allowsChildren)
            allowsChildren = allows;
            if (!allowsChildren)
                removeAllChildren();
     * Returns the child at the specified index in this node's child array.
     * @param     index     an index into this node's child array
     * @exception     ArrayIndexOutOfBoundsException     if <code>index</code>
     *                              is out of bounds
     * @return     the TreeNode in this node's child array at  the specified index
    public javax.swing.tree.TreeNode getChildAt(int index)
        if (children == null)
            throw new ArrayIndexOutOfBoundsException("node has no children");
        return (TreeNode)children.elementAt(index);
     * Returns the number of children of this node.
     * @return     an int giving the number of children of this node
    public int getChildCount()
        if (children == null)
            return 0;
        else
            return children.size();
     * Returns the index of the specified child in this node's child array.
     * If the specified node is not a child of this node, returns
     * <code>-1</code>.  This method performs a linear search and is O(n)
     * where n is the number of children.
     * @param     aChild     the TreeNode to search for among this node's children
     * @exception     IllegalArgumentException     if <code>aChild</code>
     *                                   is null
     * @return     an int giving the index of the node in this node's child
     *          array, or <code>-1</code> if the specified node is a not
     *          a child of this node
    public int getIndex(TreeNode aChild)
        if (aChild == null)
            throw new IllegalArgumentException("argument is null");
        if (!isNodeChild(aChild))
            return -1;
        return children.indexOf(aChild);     // linear search
     * Returns this node's parent or null if this node has no parent.
     * @return     this node's parent TreeNode, or null if this node has no parent
    public TreeNode getParent()
        return parent;
     * Removes <code>newChild</code> from its present parent (if it has a
     * parent), sets the child's parent to this node, and then adds the child
     * to this node's child array at index <code>childIndex</code>.
     * <code>newChild</code> must not be null and must not be an ancestor of
     * this node.
     * @param     newChild     the MutableTreeNode to insert under this node
     * @param     childIndex     the index in this node's child array
     *                    where this node is to be inserted
     * @exception     ArrayIndexOutOfBoundsException     if
     *                    <code>childIndex</code> is out of bounds
     * @exception     IllegalArgumentException     if
     *                    <code>newChild</code> is null or is an
     *                    ancestor of this node
     * @exception     IllegalStateException     if this node does not allow
     *                              children
     * @see     #isNodeDescendant
    public void insert(MutableTreeNode newChild, int childIndex)
        if (!allowsChildren)
            throw new IllegalStateException("node does not allow children");
        else if (newChild == null)
            throw new IllegalArgumentException("new child is null");
        else if (isNodeAncestor(newChild))
            throw new IllegalArgumentException("new child is an ancestor");
        MutableTreeNode oldParent = (MutableTreeNode)newChild.getParent();
        if (oldParent != null)
            oldParent.remove(newChild);
        newChild.setParent(this);
        if (children == null)
            children = new Vector();
        children.insertElementAt(newChild, childIndex);
    public boolean isLeaf()
        return !nodeElement.hasChildren();
     * Removes the child at the specified index from this node's children
     * and sets that node's parent to null. The child node to remove
     * must be a <code>MutableTreeNode</code>.
     * @param     childIndex     the index in this node's child array
     *                    of the child to remove
     * @exception     ArrayIndexOutOfBoundsException     if
     *                    <code>childIndex</code> is out of bounds
    public void remove(int childIndex)
        MutableTreeNode child = (MutableTreeNode)getChildAt(childIndex);
        children.removeElementAt(childIndex);
        child.setParent(null);
     * Removes <code>aChild</code> from this node's child array, giving it a
     * null parent.
     * @param     aChild     a child of this node to remove
     * @exception     IllegalArgumentException     if <code>aChild</code>
     *                         is null or is not a child of this node
    public void remove(MutableTreeNode aChild)
        if (aChild == null)
            throw new IllegalArgumentException("argument is null");
        if (!isNodeChild(aChild))
            throw new IllegalArgumentException("argument is not a child");
        remove(getIndex(aChild));     // linear search
     * Removes the subtree rooted at this node from the tree, giving this
     * node a null parent.  Does nothing if this node is the root of its
     * tree.
    public void removeFromParent()
        MutableTreeNode parent = (MutableTreeNode)getParent();
        if (parent != null)
            parent.remove(this);
     * Sets this node's parent to <code>newParent</code> but does not
     * change the parent's child array.  This method is called from
     * <code>insert()</code> and <code>remove()</code> to
     * reassign a child's parent, it should not be messaged from anywhere
     * else.
     * @param     newParent     this node's new parent
    public void setParent(MutableTreeNode mutableTreeNode)
        this.parent = parent;
    public void setUserObject(Object obj)
        this.userObject = obj;
    public Element getXMLElement()
        return this.nodeElement;
    public String toString()
        return this.nodeElement.getTextTrim();
     * Returns true if <code>anotherNode</code> is an ancestor of this node
     * -- if it is this node, this node's parent, or an ancestor of this
     * node's parent.  (Note that a node is considered an ancestor of itself.)
     * If <code>anotherNode</code> is null, this method returns false.  This
     * operation is at worst O(h) where h is the distance from the root to
     * this node.
     * @see          #isNodeDescendant
     * @see          #getSharedAncestor
     * @param     anotherNode     node to test as an ancestor of this node
     * @return     true if this node is a descendant of <code>anotherNode</code>
    public boolean isNodeAncestor(TreeNode anotherNode)
        if (anotherNode == null)
            return false;
        TreeNode ancestor = this;
        do
            if (ancestor == anotherNode)
                return true;
        } while((ancestor = ancestor.getParent()) != null);
        return false;
     * Returns true if <code>aNode</code> is a child of this node.  If
     * <code>aNode</code> is null, this method returns false.
     * @return     true if <code>aNode</code> is a child of this node; false if
     *            <code>aNode</code> is null
    public boolean isNodeChild(TreeNode aNode)
        boolean retval;
        if (aNode == null)
            retval = false;
        else
            if (getChildCount() == 0)
                retval = false;
            else
                retval = (aNode.getParent() == this);
        return retval;
     * Removes all of this node's children, setting their parents to null.
     * If this node has no children, this method does nothing.
    public void removeAllChildren()
        for (int i = getChildCount()-1; i >= 0; i--)
            remove(i);
     * Removes <code>newChild</code> from its parent and makes it a child of
     * this node by adding it to the end of this node's child array.
     * @see          #insert
     * @param     newChild     node to add as a child of this node
     * @exception     IllegalArgumentException    if <code>newChild</code>
     *                              is null
     * @exception     IllegalStateException     if this node does not allow
     *                              children
    public void add(MutableTreeNode newChild)
        if(newChild != null && newChild.getParent() == this)
            insert(newChild, getChildCount() - 1);
        else
            insert(newChild, getChildCount());
     * Indicates whether some other object is "equal to" this one.
     * @param   obj   the reference object with which to compare.
     * @return  <code>true</code> if this object is the same as the obj
     *          argument; <code>false</code> otherwise.
    public boolean equals(XMLNode node)
        boolean retValue;
        retValue = (this.getXMLElement().getTextTrim().equals(node.getXMLElement().getTextTrim())) &&
                (this.getXMLElement().getParent().getTextTrim().equals(node.getXMLElement().getParent().getTextTrim()));
        return retValue;
* XMLTreeModel.java
* Created on December 20, 2004, 11:29 AM
package debopam.utils.xml;
import java.io.File;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.EventListener;
import java.util.List;
import java.util.Vector;
import javax.swing.event.EventListenerList;
import javax.swing.event.TreeModelEvent;
import javax.swing.event.TreeModelListener;
import javax.swing.tree.TreeModel;
import javax.swing.tree.TreePath;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.input.SAXBuilder;
* @author Debopam Ghoshal
public class XMLTreeModel implements TreeModel
    private XMLNode rootNode;
    private String xmlFileName;
    private Document xmlDocument;
    /** Listeners. */
    protected EventListenerList listenerList = new EventListenerList();
     * Determines how the <code>isLeaf</code> method figures
     * out if a node is a leaf node. If true, a node is a leaf
     * node if it does not allow children. (If it allows
     * children, it is not a leaf node, even if no children
     * are present.) That lets you distinguish between <i>folder</i>
     * nodes and <i>file</i> nodes in a file system, for example.
     * <p>
     * If this value is false, then any node which has no
     * children is a leaf node, and any node may acquire
     * children.
     * @see TreeNode#getAllowsChildren
     * @see TreeModel#isLeaf
     * @see #setAsksAllowsChildren
    protected boolean asksAllowsChildren;
    /** Creates a new instance of XMLTreeModel */
    public XMLTreeModel(String xmlFileName, boolean asksAllowsChildren)
        this.xmlFileName = xmlFileName;
        this.asksAllowsChildren = asksAllowsChildren;
        loadXMLDocument();
        rootNode = makeRootNode();
    public XMLTreeModel(String xmlFileName)
        this(xmlFileName, false);
    private void loadXMLDocument()
        System.out.println("loading xml document...");
        try
            this.xmlDocument = null;
            this.xmlDocument = new SAXBuilder().build(new File(xmlFileName));
        catch(Exception x)
            System.out.println("Error while loading XML Document.");
            x.printStackTrace();
    private XMLNode makeRootNode()
        XMLNode root = new XMLNode(xmlDocument.getRootElement(), true);
        addChildren(root, xmlDocument.getRootElement());
        return root;
    private void addChildren(XMLNode parentXMLNode, Element element)
        List children = element.getChildren();
        for(int i = 0; i < children.size(); i++)
            Element childElement = (Element)children.get(i);
            XMLNode childNode = new XMLNode(childElement, true);
            parentXMLNode.add(childNode);
            addChildren(childNode, childElement);
     * Sets whether or not to test leafness by asking getAllowsChildren()
     * or isLeaf() to the TreeNodes.  If newvalue is true, getAllowsChildren()
     * is messaged, otherwise isLeaf() is messaged.
    public void setAsksAllowsChildren(boolean newValue)
        asksAllowsChildren = newValue;
     * Tells how leaf nodes are determined.
     * @return true if only nodes which do not allow children are
     *         leaf nodes, false if nodes which have no children
     *         (even if allowed) are leaf nodes
     * @see #asksAllowsChildren
    public boolean asksAllowsChildren()
        return asksAllowsChildren;
     * Returns the child of <I>parent</I> at index <I>index</I> in the parent's
     * child array.  <I>parent</I> must be a node previously obtained from
     * this data source. This should not return null if <i>index</i>
     * is a valid index for <i>parent</i> (that is <i>index</i> >= 0 &&
     * <i>index</i> < getChildCount(<i>parent</i>)).
     * @param   parent  a node in the tree, obtained from this data source
     * @return  the child of <I>parent</I> at index <I>index</I>
    public Object getChild(Object parent, int index)
        return ((XMLNode)parent).getChildAt(index);
     * Returns the number of children of <I>parent</I>.  Returns 0 if the node
     * is a leaf or if it has no children.  <I>parent</I> must be a node
     * previously obtained from this data source.
     * @param   parent  a node in the tree, obtained from this data source
     * @return  the number of children of the node <I>parent</I>
    public int getChildCount(Object parent)
        return ((XMLNode)parent).getChildCount();
     * Returns the index of child in parent.
     * If either the parent or child is <code>null</code>, returns -1.
     * @param parent a note in the tree, obtained from this data source
     * @param child the node we are interested in
     * @return the index of the child in the parent, or -1
     *    if either the parent or the child is <code>null</code>
    public int getIndexOfChild(Object parent, Object child)
        if(parent == null || child == null)
            return -1;
        return ((XMLNode)parent).getIndex((XMLNode)child);
     * Sets the root to <code>root</code>. A null <code>root</code> implies
     * the tree is to display nothing, and is legal.
    public void setRoot(XMLNode rootNode)
        Object oldRoot = this.rootNode;
        this.rootNode = rootNode;
        if (rootNode == null && oldRoot != null)
            fireTreeStructureChanged(this, null);
        else
            nodeStructureChanged(rootNode);
     * Returns the root of the tree.  Returns null only if the tree has
     * no nodes.
     * @return  the root of the tree
    public Object getRoot()
        return rootNode;
     * Returns whether the specified node is a leaf node.
     * The way the test is performed depends on the
     * <code>askAllowsChildren</code> setting.
     * @param node the node to check
     * @return true if the node is a leaf node
     * @see #asksAllowsChildren
     * @see TreeModel#isLeaf
    public boolean isLeaf(Object node)
        if(asksAllowsChildren)
            return !((XMLNode)node).getAllowsChildren();
        return ((XMLNode)node).isLeaf();
     * This sets the user object of the TreeNode identified by path
     * and posts a node changed.  If you use custom user objects in
     * the TreeModel you're going to need to subclass this and
     * set the user object of the changed node to something meaningful.
    public void valueForPathChanged(TreePath path, Object newValue)
        XMLNode aNode = (XMLNode)path.getLastPathComponent();
        aNode.setUserObject(newValue);
        nodeChanged(aNode);
     * Invoked this to insert newChild at location index in parents children.
     * This will then message nodesWereInserted to create the appropriate
     * event. This is the preferred way to add children as it will create
     * the appropriate event.
    public void insertNodeInto(XMLNode newChild, XMLNode parent, int index)
        parent.insert(newChild, index);
        int[] newIndexs = new int[1];
        newIndexs[0] = index;
        nodesWereInserted(parent, newIndexs);
     * Message this to remove node from its parent. This will message
     * nodesWereRemoved to create the appropriate event. This is the
     * preferred way to remove a node as it handles the event creation
     * for you.
    public void removeNodeFromParent(XMLNode node)
        XMLNode parent = (XMLNode)node.getParent();
        if(parent == null)
            throw new IllegalArgumentException("node does not have a parent.");
        int[] childIndex = new int[1];
        Object[] removedArray = new Object[1];
        childIndex[0] = parent.getIndex(node);
        parent.remove(childIndex[0]);
        removedArray[0] = node;
        nodesWereRemoved(parent, childIndex, removedArray);
     * Invoke this method after you've changed how node is to be
     * represented in the tree.
    public void nodeChanged(XMLNode node)
        if(listenerList != null && node != null)
            XMLNode parent = (XMLNode)node.getParent();
            if(parent != null)
                int        anIndex = parent.getIndex(node);
                if(anIndex != -1)
                    int[] cIndexs = new int[1];
                    cIndexs[0] = anIndex;
                    nodesChanged(parent, cIndexs);
            else if (node == getRoot())
                nodesChanged(node, null);
     * Invoke this method if you've modified the TreeNodes upon which this
     * model depends.  The model will notify all of its listeners that the
     * model has changed.
    public void reload()
        loadXMLDocument();
        XMLNode tempRootNode = makeRootNode();
        if(!tempRootNode.equals(rootNode))
            // Means that the root node itself has changed.
            System.out.println("Root node changed");
            reload(rootNode);
        //else
            checkForNodesChanged(tempRootNode, rootNode);
     * Invoke this method if you've modified the TreeNodes upon which this
     * model depends.  The model will notify all of its listeners that the
     * model has changed below the node <code>node</code> (PENDING).
    public void reload(XMLNode node)
        if(node != null)
            fireTreeStructureChanged(this, getPathToRoot(node), null, null);
     * Invoke this method after you've inserted some TreeNodes into
     * node.  childIndices should be the index of the new elements and
     * must be sorted in ascending order.
    public void nodesWereInserted(XMLNode node, int[] childIndices)
        if(listenerList != null && node != null && childIndices != null
                && childIndices.length > 0)
            int               cCount = childIndices.length;
            Object[]          newChildren = new Object[cCount];
            for(int counter = 0; counter < cCount; counter++)
                newChildren[counter] = node.getChildAt(childIndices[counter]);
            fireTreeNodesInserted(this, getPathToRoot(node), childIndices,
                    newChildren);
     * Invoke this method after you've removed some TreeNodes from
     * node.  childIndices should be the index of the removed elements and
     * must be sorted in ascending order. And removedChildren should be
     * the array of the children objects that were removed.
    public void nodesWereRemoved(XMLNode node, int[] childIndices,
            Object[] removedChildren)
        if(node != null && childIndices != null)
            fireTreeNodesRemoved(this, getPathToRoot(node), childIndices,
                    removedChildren);
     * Invoke this method after you've changed how the children identified by
     * childIndicies are to be represented in the tree.
    public void nodesChanged(XMLNode node, int[] childIndices)
        if(node != null)
            if (childIndices != null)
                int cCount = childIndices.length;
                if(cCount > 0)
                    Object[] cChildren = new Object[cCount];
                    for(int counter = 0; counter < cCount; counter++)
                        cChildren[counter] = node.getChildAt
                                (childIndices[counter]);
                    fireTreeNodesChanged(this, getPathToRoot(node),
                            childIndices, cChildren);
            else if (node == getRoot())
                fireTreeNodesChanged(this, getPathToRoot(node), null, null);
     * Invoke this method if you've totally changed the children of
     * node and its childrens children...  This will post a
     * treeStructureChanged event.
    public void nodeStructureChanged(XMLNode node)
        if(node != null)
            fireTreeStructureChanged(this, getPathToRoot(node), null, null);
     * Builds the parents of node up to and including the root node,
     * where the original node is the last element in the returned array.
     * The length of the returned array gives the node's depth in the
     * tree.
     * @param aNode the TreeNode to get the path for
    public XMLNode[] getPathToRoot(XMLNode aNode)
        return getPathToRoot(aNode, 0);
     * Builds the parents of node up to and including the root node,
     * where the original node is the last element in the returned array.
     * The length of the returned array gives the node's depth in the
     * tree.
     * @param aNode  the TreeNode to get the path for
     * @param depth  an int giving the number of steps already taken towards
     *        the root (on recursive calls), used to size the returned array
     * @return an array of TreeNodes giving the path from the root to the
     *         specified node
    protected XMLNode[] getPathToRoot(XMLNode aNode, int depth)
        XMLNode[] retNodes;
        // This method recurses, traversing towards the root in order
        // size the array. On the way back, it fills in the nodes,
        // starting from the root and working back to the original node.
        /* Check for null, in case someone passed in a null node, or
           they passed in an element that isn't rooted at root. */
        if(aNode == null)
            if(depth == 0)
                return null;
            else
                retNodes = new XMLNode[depth];
        else
            depth++;
            if(aNode == rootNode)
                retNodes = new XMLNode[depth];
            else
                retNodes = getPathToRoot((XMLNode)aNode.getParent(), depth);
            retNodes[retNodes.length - depth] = aNode;
        return retNodes;
    //  Events
     * Adds a listener for the TreeModelEvent posted after the tree changes.
     * @see     #removeTreeModelListener
     * @param   l       the listener to add
    public void addTreeModelListener(TreeModelListener l)
        listenerList.add(TreeModelListener.class, l);
     * Removes a listener previously added with <B>addTreeModelListener()</B>.
     * @see     #addTreeModelListener
     * @param   l       the listener to remove
    public void removeTreeModelListener(TreeModelListener l)
        listenerList.remove(TreeModelListener.class, l);
     * Returns an array of all the tree model listeners
     * registered on this model.
     * @return all of this model's <code>TreeModelListener</code>s
     *         or an empty
     *         array if no tree model listeners are currently registered
     * @see #addTreeModelListener
     * @see #removeTreeModelListener
     * @since 1.4
    public TreeModelListener[] getTreeModelListeners()
        return (TreeModelListener[])listenerList.getListeners(
                TreeModelListener.class);
     * Notifies all listeners that have registered interest for
     * notification on this event type.  The event instance
     * is lazily created using the parameters passed into
     * the fire method.
     * @param source the node being changed
     * @param path the path to the root node
     * @param childIndices the indices of the changed elements
     * @param children the changed elements
     * @see EventListenerList
    protected void fireTreeNodesChanged(Object source, Object[] path,
            int[] childIndices,
            Object[] children)
        // Guaranteed to return a non-null array
        Object[] listeners = listenerList.getListenerList();
        TreeModelEvent e = null;
        // Process the listeners last to first, notifying
        // those that are interested in this event
        for (int i = listeners.length-2; i>=0; i-=2)
            if (listeners==TreeModelListener.class)
// Lazily create the event:
if (e == null)
e = new TreeModelEvent(source, path,
childIndices, children);
((TreeModelListener)listeners[i+1]).treeNodesChanged(e);
* Notifies all listeners that have registered interest for
* notification on this event type. The event instance

Similar Messages

  • JTree with XML content expand/collapse problem

    Hello all,
    I'm having this very weird problem with a JTree I use to display the contents of an XML file. I use the DOM parser (and not JDOM since I want the application to run as an applet as well, and don't want to have any external libraries for the user to download) and have a custom TreeModel and TreeNode implementations to wrap the DOM nodes so that they are displayed by the JTree.
    I have also added a popup menu in the tree, for the user to be able to expand/collapse all nodes under the selected one (i.e. a recursive method).
    When expandAll is run, everything works fine and the children of the selected node are expanded (and their children and so on).
    However, after the expansion when I run the collapseAll function, even though the selected node collapses, when I re-expand it (manually not by expandAll) all of it's children are still fully open! Even if I collapse sub-elements of the node manually and then collapse this node and re-expand it, it "forgets" the state of it's children and shows them fully expanded.
    In other words once I use expandAll no matter what I do, the children of this node will be expanded (once I close it and re-open it).
    Also after running expandAll the behaviour(!) of the expanded nodes change: i have tree.setToggleClickCount(1); but on the expanded nodes I need to double-click to collapse them.
    I believe the problem is related to my implementations of TreeModel and TreeNode but after many-many hours of trying to figure out what's happening I'm desperate... Please help!
    Here's my code:
    public class XMLTreeNode implements TreeNode 
         //This class wraps a DOM node
        org.w3c.dom.Node domNode;
        protected boolean allowChildren;
        protected Vector children;
        //compressed view (#text).
         private static boolean compress = true;   
        // An array of names for DOM node-types
        // (Array indexes = nodeType() values.)
        static final String[] typeName = {
            "none",
            "Element",
            "Attr",
            "Text",
            "CDATA",
            "EntityRef",
            "Entity",
            "ProcInstr",
            "Comment",
            "Document",
            "DocType",
            "DocFragment",
            "Notation",
        static final int ELEMENT_TYPE =   1;
        static final int ATTR_TYPE =      2;
        static final int TEXT_TYPE =      3;
        static final int CDATA_TYPE =     4;
        static final int ENTITYREF_TYPE = 5;
        static final int ENTITY_TYPE =    6;
        static final int PROCINSTR_TYPE = 7;
        static final int COMMENT_TYPE =   8;
        static final int DOCUMENT_TYPE =  9;
        static final int DOCTYPE_TYPE =  10;
        static final int DOCFRAG_TYPE =  11;
        static final int NOTATION_TYPE = 12;
        // The list of elements to display in the tree
       static String[] treeElementNames = {
            "node",
      // Construct an Adapter node from a DOM node
      public XMLTreeNode(org.w3c.dom.Node node) {
        domNode = node;
      public String toString(){
           if (domNode.hasAttributes()){
                return domNode.getAttributes().getNamedItem("label").getNodeValue();
           }else return domNode.getNodeName();      
      public boolean isLeaf(){ 
           return (this.getChildCount()==0);
      boolean treeElement(String elementName) {
          for (int i=0; i<treeElementNames.length; i++) {
            if ( elementName.equals(treeElementNames)) return true;
    return false;
    public int getChildCount() {
         if (!compress) {   
    return domNode.getChildNodes().getLength();
    int count = 0;
    for (int i=0; i<domNode.getChildNodes().getLength(); i++) {
    org.w3c.dom.Node node = domNode.getChildNodes().item(i);
    if (node.getNodeType() == ELEMENT_TYPE
    && treeElement( node.getNodeName() ))
    // Note:
    // Have to check for proper type.
    // The DOCTYPE element also has the right name
    ++count;
    return count;
    public boolean getAllowsChildren() {
         // TODO Auto-generated method stub
         return true;
    public Enumeration children() {
         // TODO Auto-generated method stub
         return null;
    public TreeNode getParent() {
         // TODO Auto-generated method stub
         return null;
    public TreeNode getChildAt(int searchIndex) {
    org.w3c.dom.Node node =
    domNode.getChildNodes().item(searchIndex);
    if (compress) {
    // Return Nth displayable node
    int elementNodeIndex = 0;
    for (int i=0; i<domNode.getChildNodes().getLength(); i++) {
    node = domNode.getChildNodes().item(i);
    if (node.getNodeType() == ELEMENT_TYPE
    && treeElement( node.getNodeName() )
    && elementNodeIndex++ == searchIndex) {
    break;
    return new XMLTreeNode(node);
    public int getIndex(TreeNode tnode) {
         if (tnode== null) {
              throw new IllegalArgumentException("argument is null");
         XMLTreeNode child=(XMLTreeNode)tnode;
         int count = getChildCount();
         for (int i=0; i<count; i++) {
              XMLTreeNode n = (XMLTreeNode)this.getChildAt(i);
              if (child.domNode == n.domNode) return i;
         return -1; // Should never get here.
    public class XMLTreeModel2 extends DefaultTreeModel
         private Vector listenerList = new Vector();
         * This adapter converts the current Document (a DOM) into
         * a JTree model.
         private Document document;
         public XMLTreeModel2 (Document doc){
              super(new XMLTreeNode(doc));
              this.document=doc;
         public Object getRoot() {
              //System.err.println("Returning root: " +document);
              return new XMLTreeNode(document);
         public boolean isLeaf(Object aNode) {
              return ((XMLTreeNode)aNode).isLeaf();
         public int getChildCount(Object parent) {
              XMLTreeNode node = (XMLTreeNode) parent;
    return node.getChildCount();
         public Object getChild(Object parent, int index) {
    XMLTreeNode node = (XMLTreeNode) parent;
    return node.getChildAt(index);
         public int getIndexOfChild(Object parent, Object child) {
    if (parent==null || child==null )
         return -1;
              XMLTreeNode node = (XMLTreeNode) parent;
    return node.getIndex((XMLTreeNode) child);
         public void valueForPathChanged(TreePath path, Object newValue) {
    // Null. no changes
         public void addTreeModelListener(TreeModelListener listener) {
              if ( listener != null
    && ! listenerList.contains( listener ) ) {
    listenerList.addElement( listener );
         public void removeTreeModelListener(TreeModelListener listener) {
              if ( listener != null ) {
    listenerList.removeElement( listener );
         public void fireTreeNodesChanged( TreeModelEvent e ) {
    Enumeration listeners = listenerList.elements();
    while ( listeners.hasMoreElements() ) {
    TreeModelListener listener =
    (TreeModelListener) listeners.nextElement();
    listener.treeNodesChanged( e );
         public void fireTreeNodesInserted( TreeModelEvent e ) {
    Enumeration listeners = listenerList.elements();
    while ( listeners.hasMoreElements() ) {
    TreeModelListener listener =
    (TreeModelListener) listeners.nextElement();
    listener.treeNodesInserted( e );
         public void fireTreeNodesRemoved( TreeModelEvent e ) {
    Enumeration listeners = listenerList.elements();
    while ( listeners.hasMoreElements() ) {
    TreeModelListener listener =
    (TreeModelListener) listeners.nextElement();
    listener.treeNodesRemoved( e );
         public void fireTreeStructureChanged( TreeModelEvent e ) {
    Enumeration listeners = listenerList.elements();
    while ( listeners.hasMoreElements() ) {
    TreeModelListener listener =
    (TreeModelListener) listeners.nextElement();
    listener.treeStructureChanged( e );
    The collapseAll, expandAll code (even though I m pretty sure that's not the problem since they work fine on a normal JTree):
        private void collapseAll(TreePath tp){
             if (tp==null) return;
             Object node=tp.getLastPathComponent();
             TreeModel model=tree.getModel();
             if (!model.isLeaf(node)){
                  tree.collapsePath(tp);
                  for (int i=0;i<model.getChildCount(node);i++){
                  //for (int i = node.childCount()-4;i>=0;i--){
                       collapseAll(tp.pathByAddingChild(model.getChild(node,i)));
                  tree.collapsePath(tp);
        private void expandAll(TreePath tp){
             if (tp==null) return;
             Object node=tp.getLastPathComponent();
             TreeModel model=tree.getModel();
             if (!model.isLeaf(node)){
                  tree.expandPath(tp);
                  for (int i=0;i<model.getChildCount(node);i++){
                  //for (int i = node.childCount()-4;i>=0;i--){
                       expandAll(tp.pathByAddingChild(model.getChild(node,i)));

    Hi,
    Iam not facing this problem. To CollapseAll, I do a tree.getModel().reload() which causes all nodes to get collapsed and remain so even if I reopen them manually.
    Hope this helps.
    cheers,
    vidyut

  • How to display string with XML content in 4.6?

    Hi,
    I`d like to know how to display string with XML content in it for 4.6.
    4.6 has not method parse_string.
    And example like this is not helpful:
      DATA: lo_mxml    TYPE REF TO cl_xml_document.
      CREATE OBJECT lo_mxml.
      CALL METHOD lo_mxml->parse_string
        EXPORTING
          stream = gv_xml_string.
      CALL METHOD lo_mxml->display.
    Thank you.

    Hi,
    May be you can use fm SAP_CONVERT_TO_XML_FORMAT. But it have some issues with memory usage, the program consumed tons of memory during convert.

  • Polulate Text frames with XML content - PLEASE help me.

    Hi guys,
    I'm trying to import some xml data to an indesign file. Here are the steps I'm doing:
    1- create new document
    2- create master page
    3- create empty text fields in the master to be tagged
    4- import tags from xml
    5- import xml
    then it simply don't auto populate the text fields wiith the xml content.
    I've already spent about 10 hours trying to figure out what can be the problem...
    My structure in indesign (BEFORE importing XML):
    businesscards
    Card
    employeeName
    employeePosition
    employeeAddressln1
    employeeAddressln2
    employeePhone
    employeeEmail
    My structure in indesign (AFTER importing XML):
    businesscards
    Card <!-- has dropdown arrow with xml content inside -->
    Card <!-- has dropdown arrow with xml content inside -->
    Card <!-- has dropdown arrow with xml content inside -->
    Card <!-- has dropdown arrow with xml content inside -->
    employeeName
    employeePosition
    employeeAddressln1
    employeeAddressln2
    employeePhone
    employeeEmail
    But it doesn't populate the text frames...
    I've already tried to write text in the text frames and tagged them, so I can see those colored brackets. But it doesn't work and makes a mess in the structure.
    Please, can someone help me, do you know a good step by step tutorial online? What am I doing wrong?
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <businesscards>
    <Card>
    <!-- contents of Suzan Reed -->
    <employeeName>Suzan Reed</employeeName>
    <employeePosition>Director of Marketing</employeePosition>
    <employeeAddressln1>506 SE 72nd Avenue</employeeAddressln1>
    <employeeAddressln2>Portland, Oregon 97215</employeeAddressln2>
    <employeePhone>503-481-5858 direct</employeePhone>
    <employeeEmail>[email protected]</employeeEmail>
    </Card>
    <Card>
    <!-- contents of Gabriel Powell -->
    <employeeName>Gabriel Powell</employeeName>
    <employeePosition>Senior Training Director</employeePosition>
    <employeeAddressln1>25 NW 23rd Place, Suite 6-122</employeeAddressln1>
    <employeeAddressln2>Portland, Oregon 97210</employeeAddressln2>
    <employeePhone>503-515-5404 direct</employeePhone>
    <employeeEmail>[email protected]</employeeEmail>
    </Card>
    <Card>
    <!-- contents of Dale Erwing -->
    <employeeName>Dale Erwing</employeeName>
    <employeePosition>Trainer</employeePosition>
    <employeeAddressln1>5131 Buffalo Ave. #20</employeeAddressln1>
    <employeeAddressln2>Sherman Oaks, CA 91423</employeeAddressln2>
    <employeePhone>310-795-8943 cell</employeePhone>
    <employeeEmail>[email protected]</employeeEmail>
    </Card>
    <Card>
    <!-- contents of Jim Conner -->
    <employeeName>Jim Conner</employeeName>
    <employeePosition>Trainer</employeePosition>
    <employeeAddressln1>25 NW 23rd Place, Suite 6-122</employeeAddressln1>
    <employeeAddressln2>Portland, Oregon 97210</employeeAddressln2>
    <employeePhone>503-515-2376 cell</employeePhone>
    <employeeEmail>[email protected]</employeeEmail>
    </Card>
    </businesscards>
    Thanks in advance

    It worked! thanks ... But...
    But only if I don't apply to the Master when I apply to the master all the other cards have the same content as the first of the XML. :(
    Even when I try to create multiple pages (cards) with no Master page (too time consuming), I can't figure out a way of having the other cards filed with the remaining data of the XML. :(
    I don't want to drag the elements one by one to every single card (they are so many...)
    Is there a way of having the structure organized in a way to have indesign auto populate and auto create pages?
    thanks for any kind of advice.

  • Issues with XML Content and Actions to import RRA in FPN (EP7 SPS13)

    Hi,
    I am having trouble using the import functionality of XML Content and Actions to transport Remote Role Assignments between Consumer Portals. Whenever I want to upload an XML file containing RRA for Roles and Groups that were already assigned to eachother, the import fails and nothing is updated. The error I get:
    UMException. Data could not commit to Role: gp:/[full ID of portal role]
    Anyone with experience in how to use this?
    Kind regards,
    Christian Staalby

    hi,
    @Maksim :
    When user launch an URL like http://myserver:port/irj/portal/ import/*filename=C:\test.xml, he is requested to provide username and password; as this link is a shortcut for the upload xml page, there is a check of authorization and only portal admin that have authorization and permission on this page/iview will be able to upload xml file through the URL. Hope this clarify.
    @Kumar :
    thank you for your answer. What a pity to not be able to pass parameter through standard portal page/iview particularly knowing that we can pass paramater through many kinds of iviews (transactional iview, url iview, VC iview...). I explored some option on file com.sap.portal.ivs.init.par but this was unsuccessful. However, thanks to this [link bellow|http://wiki.sdn.sap.com/wiki/display/Snippets/ComponenttouploadXMLfilewithPCD+objects], I was able to upload through URL the XML file.
    The problem is that I can upload only XML file that are stored in the server not in the local user computer. My requirement is to be able to upload local XML file stored on user's computer.
    If someone could provide and idea/solution, I would be very grateful.
    Cheers

  • POST http(s) request with xml content in Power Query

    I have a POST http request which works good in HttpRequester (Firefox plugin). I know that it is possible to call POST request in Power Query but cannot find working solution. Here is the original request:
    POST https://svcs.ebay.com/FeedbackService
    X-EBAY-SOA-OPERATION-NAME: createDSRSummaryByPeriod
    X-EBAY-SOA-SERVICE-VERSION: 1.0.0
    X-EBAY-SOA-SERVICE-NAME: FeedbackService
    X-EBAY-SOA-APP-NAME: ***
    X-EBAY-SOA-SITEID: 0
    X-EBAY-SOA-SECURITY-TOKEN: ***
    Content-Type: text/xml
    <?xml version="1.0" encoding="UTF-8"?>
    <createDSRSummaryByPeriodRequest xmlns="http://www.ebay.com/marketplace/services">
    <dateRange>
    <dateFrom>2013-12-01T00:00:00.000Z</dateFrom>
    <dateTo>2013-12-31T23:59:59.999Z</dateTo>
    </dateRange>
    <dateRangeEventType>ListingDate</dateRangeEventType>
    </createDSRSummaryByPeriodRequest>
    Power Query WebContent() function is capable to handle headers and xml content, however, there is no any documentation about its syntax.
    In Power Query I use this request:
    = Xml.Tables(Web.Contents(“https://svcs.ebay.com/FeedbackService”,
    [Headers =[" X-EBAY-SOA-OPERATION-NAME"= "createDSRSummaryByPeriod",
    "X-EBAY-SOA-SERVICE-VERSION="1.0.0",
    "X-EBAY-SOA-SERVICE-NAME"="FeedbackService",
    "X-EBAY-SOA-APP-NAME"="***","X-EBAY-SOA-SITEID"="0",
    "X-EBAY-SOA-SECURITY-TOKEN"="***"],
    Content=["<?xml version="1.0" encoding="UTF-8"?>
    <createDSRSummaryByPeriodRequest xmlns="http://www.ebay.com/marketplace/services">
    <dateRange>
    <dateFrom>2013-12-01T00:00:00.000Z</dateFrom>
    <dateTo>2013-12-31T23:59:59.999Z</dateTo>
    </dateRange>
    <dateRangeEventType>ListingDate</dateRangeEventType>
    </createDSRSummaryByPeriodRequest>"]]))
    However, it returns "Expression.SyntaxError: Invalid identifier." Maybe anyone has at least examples of analogous working syntax?

    Task is solved. First of all I updated PowerQuery since previous version does not support Headers option for Web.Contents function. Here is a correct syntax:
    =Xml.Document(Web.Contents("https://api.ebay.com/ws/api.dll",[Headers=[#"X-EBAY-API-COMPATIBILITY-LEVEL"= "871",#"X-EBAY-API-SITEID"="0",#"X-EBAY-API-CALL-NAME"="GetMyeBaySelling",#"CONTENT-TYPE"="text/xml"], Content=Text.ToBinary("<?xml version="&Character.FromNumber(34)&"1.0"&Character.FromNumber(34)&" encoding="&Character.FromNumber(34)&"utf-8"&Character.FromNumber(34)&"?>
    <GetMyeBaySellingRequest xmlns="&Character.FromNumber(34)&"urn:ebay:apis:eBLBaseComponents"&Character.FromNumber(34)&">
    <RequesterCredentials><eBayAuthToken>***</eBayAuthToken></RequesterCredentials><SoldList><DurationInDays>60</DurationInDays><Pagination><EntriesPerPage>100</EntriesPerPage><PageNumber>1</PageNumber></Pagination></SoldList></GetMyeBaySellingRequest>")]))

  • Testing BPM on NWA with XML Content

    Hi SDN team,
    I'm working with SAP NetWeaver CE 7.3.
    I have modeled a BPM (based on the Microsoft OLX Web Service) and try to test it on SAP NetWeaver Administration (NWA). Therefor, I also have created a XML file. But when I upload it, the warning message "Datei kann nicht hochgeladen werden, da die Prozessdefinitions-ID für den Prozess, den Sie starten möchten, nicht übereinstimmt", that means "File cannot be uploaded, because the process definition ID for the process you try to start does not match"
    The XML file:
    <?xml version="1.0" encoding="utf-8"?>
    <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
      <soap:Header>
      <t:RequestServerVersion Version="Exchange2010_SP2"/>
      </soap:Header>
      <soap:Body>
      <FindFolder Traversal="Shallow" xmlns="http://schemas.microsoft.com/exchange/services/2006/messages">
      <FolderShape>
      <t:BaseShape>AllProperties</t:BaseShape>
      </FolderShape>
      <ParentFolderIds>
      <t:FolderId Id="AAEuAAAAAAAaRHOQqmYRzZvIAKoAL8RaAwAVb4+VoTScSajx6dP/9c40AAACQ1iEAAA="/>
      <t:DistinguishedFolderId Id="inbox"/>
      </ParentFolderIds>
      </FindFolder>
      </soap:Body>
    </soap:Envelope>
    Without the envelope, I got an error: "File not valid".
    Is there another way to define start (parameter) values? In my BPM, there is a Data Content for the process context.
    Thanks, Cheers,
    Cengiz

    Hello Cengiz,
    i don't know if i get this right. You have designed a BPM Workflow with a start trigger based on a microsoft wsdl and you want to test this now? You could start your process in NWA by navigating to Process-Repository and klick on your process definition and then click button "start process". Then you can enter start parameter. Also you could use the WSNavigator and search for your start Trigger. There you could also enter the paramters and start your process.
    BR,
    Tobi

  • Populating ComboBox with XML data

    Hi there,
    Probably the most basic question, but I'm having a hard time with this...
    Trying to populate the ComboBox with XML data as a dataProvider.
    Here is the code snippet:
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
                    layout="vertical"
                    creationComplete="baseDataRequest.send()">
        <mx:Script>
            <![CDATA[
                import mx.collections.XMLListCollection;
                import mx.rpc.events.ResultEvent;
                [Bindable]
                private var baseDataXML:XML;
                private function baseResultHandler(event:ResultEvent):void
                    baseDataXML = event.result.node.child as XML;
            ]]>
        </mx:Script>
        <mx:HTTPService id="baseDataRequest"
                        useProxy="false"
                        resultFormat="e4x"
                        result="baseResultHandler(event)"
                        url="XML_URL"/>
        <mx:ComboBox id="comboDemo"
                     width="390"
                     dataProvider="{baseDataXML}"
                     labelField="NodeName"/>
    </mx:Application>
    And that returns nothing, basically. I know the XML is being pulled, because if I do this:
    baseDataXML = event.result as XML;
    then I just see a single item in my ComboBox, with full XML content.
    How do I populate the ComboBox with XML contents?
    XML example:
    <root>
        <node>          <child>Child1</child>
              <child>Child2</child>
         </node>
    </root>
    Question: how do I populate the ComboBox with XML data nodes? I need <child> content to be the labelField of each combo box item...
    Thanks!
    K

         <mx:Script>
              <![CDATA[
                   var baseDataXML:XML = <root><node><child>Child1</child><child>Child2</child></node></root>;
              ]]>
         </mx:Script>
         <mx:ComboBox id="comboDemo"
                     width="390"
                     dataProvider="{baseDataXML.node.child}"
                     labelField="NodeName"/>
    Don't do:
    baseDataXML = event.result.node.child as XML;
    Instead just do:
    baseDataXML = XML(event.result);
    And in your combo:
    dataProvider="{baseDataXML.node.child}"

  • Error message in .docx : 'Open XML file cannot be opened because there are problems with the contents. Details Unspecific error Location: 2'

    I have put a lot of work into a docx document on my Mac, but now can't open it as it gives the error message: 'the Open XML file cannot be opened because there are problems with the contents. Details, Unspecific
    error, Location: 2'
    When opening the original file the message said: 'this file contains word 2007 for Windows equations' etc. but I managed to track changes fine, and saved, closed and re-opened it numerous times without problem. Some graphs seemed moved, and various formulas
    were illegible, but no other weirdness was observed.
    I have microsoft 2008 installed on my Mac OS X version 10.6.8.
    I've tried to fix it using various solutions suggested here, but am afraid am too IT illiterate to have had any luck, please help I'm new to all this!
    I've uploaded it to https://www.dropbox.com/s/hkw9k6lyihzoxpc/SittwayPauktawSQUEACREPORT_KD%2BCH.docx

    Hi,
    This issue is related strictly to oMath tags and occurs when a graphical object or text box is anchored to the same paragraph that contains the equation.
    Please use the "Fix it" tool in the following KB article to resolve the problem. See:
    http://support.microsoft.com/kb/2528942
    Hope this helps.
    Regards,
    Steve Fan
    TechNet Community Support

  • Catch all error information while validating xml content with xsd schema

    Hi experts,
    I created a java mapping to validating the input xml content with xsd schema (schema validation). What I want is to catch all error message to the xml not just the first error. I used SAXParser in sapxmltoolkit.jar to do the schema validation. The below is a part of my java mapping.
    XMLReader parser = XMLReaderFactory.createXMLReader("com.sap.engine.lib.xml.parser.SAXParser");
    parser.setFeature( "http://xml.org/sax/features/validation" ,  true);
    parser.setFeature( "http://apache.org/xml/features/validation/schema" , true);
    parser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema");          parser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaSource",this.getClass().getClassLoader().getResourceAsStream(schema)); // schema is my schema name
    parser.setErrorHandler(new ParseErrorHandler()); // ParseErrorHandler is my own ErrorHandler which extends DefaultHandler
    parser.parse(new InputSource(new ByteArrayInputStream(sinput.getBytes())));
    // In error handler, I comment all code so as not to throw any exception
    public class ParseErrorHandler extends DefaultHandler
         public void error(SAXParseException e) throws SAXException
              // sSystem.out.println("Error" + e.getMessage());
              // throw e;
         public void fatalError(SAXParseException e)
              // throw e;
              // System.out.println("SAP Fatal Error" + e.getMessage());
    Unfortunately the program always stopped while catching the first error. Check the below log.
    com.sap.engine.lib.xml.parser.NestedSAXParserException: Fatal Error: com.sap.engine.lib.xml.parser.ParserException:
    ERRORS :
    cvc-simple-type : information item '/:ShipNotice[1]/:Header[1]/:To[1]/:PartnerInformation[1]/:AddressInformation[1]/:CityName[1]' is not valid, because it's value does not satisfy the constraints of facet 'minLength' with value '1'.
    cvc-data : information item '/:ShipNotice[1]/:Header[1]/:To[1]/:PartnerInformation[1]/:AddressInformation[1]/:CityName[1]' is is not valid with respoct to the corresponding simple type definition.
    cvc-element : element information item '/:ShipNotice[1]/:Header[1]/:To[1]/:PartnerInformation[1]/:AddressInformation[1]/:CityName[1]' is associated with invalid data.
    cvc-element : element information item '/:ShipNotice[1]/:Header[1]/:To[1]/:PartnerInformation[1]/:AddressInformation[1]' is not valid with respect to it's complex type definition..
    cvc-element : element information item '/:ShipNotice[1]/:Header[1]/:To[1]/:PartnerInformation[1]' is not valid with respect to it's complex type definition..
    cvc-element : element information item '/:ShipNotice[1]/:Header[1]/:To[1]' is not valid with respect to it's complex type definition..
    cvc-element : element information item '/:ShipNotice[1]/:Header[1]' is not valid with respect to it's complex type definition..
    cvc-element : element information item '/:ShipNotice[1]' is not valid with respect to it's complex type definition..
    -> com.sap.engine.lib.xml.parser.ParserException:
    I tried using Xerces and JAXP to do validation, the same error happened. I have no idea on this. Does xi has its own error handler logic? Is there any body can make me get out of this?
    Thanks.

    <h6>Hi experts,
    <h6>
    <h6>I created a java mapping to validating the input xml content with xsd schema (schema validation). What I want is to catch all <h6>error message to the xml not just the first error. I used SAXParser in sapxmltoolkit.jar to do the schema validation. The below <h6>is a part of my java mapping.
    <h6>XMLReader parser = XMLReaderFactory.createXMLReader("com.sap.engine.lib.xml.parser.SAXParser");
    <h6>parser.setFeature( "http://xml.org/sax/features/validation" ,  true);
    <h6>parser.setFeature( "http://apache.org/xml/features/validation/schema" , true);
    <h6>parser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema");          <h6>parser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaSource",this.getClass().getClassLoader().getResourceAsStream(schema)); <h6>// schema is my schema name
    <h6>parser.setErrorHandler(new ParseErrorHandler()); // ParseErrorHandler is my own ErrorHandler which extends Default Handler
    <h6>parser.parse(new InputSource(new ByteArrayInputStream(sinput.getBytes())));
    <h6>
    <h6>// In error handler, I comment all code so as not to throw any exception
    <h6>public class ParseErrorHandler extends DefaultHandler
    <h6>{
    <h6>     public void error(SAXParseException e) throws SAXException
    <h6>     {
    <h6>          // sSystem.out.println("Error" + e.getMessage());
    <h6>          // throw e;
    <h6>     }
    <h6>
    <h6>     public void fatalError(SAXParseException e)
    <h6>     {
    <h6>          // throw e;
    <h6>          // System.out.println("SAP Fatal Error" + e.getMessage());
    <h6>
    <h6>     }
    <h6>
    <h6>}
    <h6>
    <h6>Unfortunately the program always stopped while catching the first error. Check the below log.
    <h6>
    <h6>com.sap.engine.lib.xml.parser.NestedSAXParserException: Fatal Error: com.sap.engine.lib.xml.parser.ParserException:
    <h6>ERRORS :
    <h6>cvc-simple-type : information item <h6>'/:ShipNotice[1]/:Header[1]/:To[1]/:PartnerInformation[1]/:AddressInformation[1]/:CityName[1]' <h6>is not valid, because it's value does not satisfy the constraints of facet 'minLength' with value '1'.
    <h6>cvc-data : information item <h6>'/:ShipNotice[1]/:Header[1]/:To[1]/:PartnerInformation[1]/:AddressInformation[1]/:CityName[1]' <h6>is is not valid with respoct to the corresponding simple type definition.
    <h6>cvc-element : element information item <h6>'/:ShipNotice[1]/:Header[1]/:To[1]/:PartnerInformation[1]/:AddressInformation[1]/:CityName[1]' <h6>is associated with invalid data.
    <h6>cvc-element : element information item <h6>'/:ShipNotice[1]/:Header[1]/:To[1]/:PartnerInformation[1]/:AddressInformation[1]' <h6>is not valid with respect to it's complex type definition..
    <h6>cvc-element : element information item <h6>'/:ShipNotice[1]/:Header[1]/:To[1]/:PartnerInformation[1]' <h6>is not valid with respect to it's complex type definition..
    <h6>cvc-element : element information item <h6>'/:ShipNotice[1]/:Header[1]/:To[1]' <h6>is not valid with respect to it's complex type definition..
    <h6>cvc-element : element information item <h6>'/:ShipNotice[1]/:Header[1]' <h6>is not valid with respect to it's complex type definition..
    <h6>cvc-element : element information item '/:ShipNotice[1]' is not valid with <h6>respect to it's complex type definition..
    <h6> -> com.sap.engine.lib.xml.parser.ParserException:
    <h6>
    <h6>
    <h6>I tried using Xerces and JAXP to do validation, the same error happened. I have no idea on this. Does xi has its own error <h6>handler logic? Is there any body can make me get out of this?
    <h6>Thanks.

  • Performance question on small XML content but with large volume

    Hi all,
    I am new to Berkeley XML DB.
    I have the following simple XML content:
    <s:scxml xmlns:s="http://www.w3.org/2005/07/scxml">
    <s:state id="a"/>
    <s:state id="b"/>
    <s:state id="c"/>
    </s:scxml>
    about 1.5K bytes each but the total number of such content is large (5 million+ records).
    This is a typical query:
    query 'count(collection("test.dbxml")/s:scxml/s:state[@id="a"]/following-sibling::s:state[@id="e"])'
    where the id attribute is used heavily.
    I've tested with about 10000 records with the following indexes:
    Index: edge-attribute-equality-string for node {}:id
    Index: unique-node-metadata-equality-string for node {http://www.sleepycat.com/2002/dbxml}:name
    Index: edge-element-presence-none for node {}:scxml
    Index: edge-element-presence-none for node {}:state
    but the query took just under one minute to complete. Is this the expected performance? It seems slow. Is there anyway to speed it up?
    In addition, the total size of the XML content is about 12M but ~100M of data is generated with the log.xxxxxxxxxx files. Is this expected?
    Thanks.

    Hi Ron,
    Yes, I've noticed the URI issue after sending the post and changed them to:
    dbxml> listindex
    Default Index: none
    Index: edge-attribute-equality-string for node {http://www.w3.org/2005/07/scxml}
    :id
    Index: unique-node-metadata-equality-string for node {http://www.sleepycat.com/2
    002/dbxml}:name
    Index: edge-element-presence-none for node {http://www.w3.org/2005/07/scxml}:scx
    ml
    Index: edge-element-presence-none for node {http://www.w3.org/2005/07/scxml}:sta
    te
    5 indexes found.
    I added more records (total ~30000) but the query still took ~1 minute and 20 seconds to run. Here is the query plan:
    dbxml> queryplan 'count(collection("test.dbxml")/s:scxml/s:state[@id="start"]/fo
    llowing-sibling::s:state[@id="TryToTransfer"])'
    <XQuery>
    <Function name="{http://www.w3.org/2005/xpath-functions}:count">
    <DocumentOrder>
    <DbXmlNav>
    <QueryPlanFunction result="collection" container="test.dbxml">
    <OQPlan>n(P(edge-element-presence-none,=,root:http://www.sleepycat.com
    /2002/dbxml.scxml:http://www.w3.org/2005/07/scxml),P(edge-element-presence-none,
    =,scxml:http://www.w3.org/2005/07/scxml.state:http://www.w3.org/2005/07/scxml))<
    /OQPlan>
    </QueryPlanFunction>
    <DbXmlStep axis="child" prefix="s" uri="http://www.w3.org/2005/07/scxml"
    name="scxml" nodeType="element"/>
    <DbXmlStep axis="child" prefix="s" uri="http://www.w3.org/2005/07/scxml"
    name="state" nodeType="element"/>
    <DbXmlFilter>
    <DbXmlCompare name="equal" join="attribute" name="id" nodeType="attrib
    ute">
    <Sequence>
    <AnyAtomicTypeConstructor value="start" typeuri="http://www.w3.org
    /2001/XMLSchema" typename="string"/>
    </Sequence>
    </DbXmlCompare>
    </DbXmlFilter>
    <DbXmlStep axis="following-sibling" prefix="s" uri="http://www.w3.org/20
    05/07/scxml" name="state" nodeType="element"/>
    <DbXmlFilter>
    <DbXmlCompare name="equal" join="attribute" name="id" nodeType="attrib
    ute">
    <Sequence>
    <AnyAtomicTypeConstructor value="TryToTransfer" typeuri="http://ww
    w.w3.org/2001/XMLSchema" typename="string"/>
    </Sequence>
    </DbXmlCompare>
    </DbXmlFilter>
    </DbXmlNav>
    </DocumentOrder>
    </Function>
    </XQuery>
    I've noticed the indexes with URI were not used so I added back the indexes without URI:
    dbxml> listindex
    Default Index: none
    Index: edge-attribute-equality-string for node {}:id
    Index: edge-attribute-equality-string for node {http://www.w3.org/2005/07/scxml}
    :id
    Index: unique-node-metadata-equality-string for node {http://www.sleepycat.com/2
    002/dbxml}:name
    Index: edge-element-presence-none for node {}:scxml
    Index: edge-element-presence-none for node {http://www.w3.org/2005/07/scxml}:scx
    ml
    Index: edge-element-presence-none for node {}:state
    Index: edge-element-presence-none for node {http://www.w3.org/2005/07/scxml}:sta
    te
    8 indexes found.
    Here is the query plan with the above indexes:
    dbxml> queryplan 'count(collection("test.dbxml")/s:scxml/s:state[@id="start"]/fo
    llowing-sibling::s:state[@id="TryToTransfer"])'
    <XQuery>
    <Function name="{http://www.w3.org/2005/xpath-functions}:count">
    <DocumentOrder>
    <DbXmlNav>
    <QueryPlanFunction result="collection" container="test.dbxml">
    <OQPlan>n(P(edge-element-presence-none,=,root:http://www.sleepycat.com
    /2002/dbxml.scxml:http://www.w3.org/2005/07/scxml),P(edge-element-presence-none,
    =,scxml:http://www.w3.org/2005/07/scxml.state:http://www.w3.org/2005/07/scxml),V
    (edge-attribute-equality-string,state:http://www.w3.org/2005/07/scxml.@id,=,'sta
    rt'),V(edge-attribute-equality-string,state:http://www.w3.org/2005/07/scxml.@id,
    =,'TryToTransfer'))</OQPlan>
    </QueryPlanFunction>
    <DbXmlStep axis="child" prefix="s" uri="http://www.w3.org/2005/07/scxml"
    name="scxml" nodeType="element"/>
    <DbXmlStep axis="child" prefix="s" uri="http://www.w3.org/2005/07/scxml"
    name="state" nodeType="element"/>
    <DbXmlFilter>
    <DbXmlCompare name="equal" join="attribute" name="id" nodeType="attrib
    ute">
    <Sequence>
    <AnyAtomicTypeConstructor value="start" typeuri="http://www.w3.org
    /2001/XMLSchema" typename="string"/>
    </Sequence>
    </DbXmlCompare>
    </DbXmlFilter>
    <DbXmlStep axis="following-sibling" prefix="s" uri="http://www.w3.org/20
    05/07/scxml" name="state" nodeType="element"/>
    <DbXmlFilter>
    <DbXmlCompare name="equal" join="attribute" name="id" nodeType="attrib
    ute">
    <Sequence>
    <AnyAtomicTypeConstructor value="TryToTransfer" typeuri="http://ww
    w.w3.org/2001/XMLSchema" typename="string"/>
    </Sequence>
    </DbXmlCompare>
    </DbXmlFilter>
    </DbXmlNav>
    </DocumentOrder>
    </Function>
    </XQuery>
    The indexes are used in this case and the execution time was reduced to about 40 seconds. I set the namespace with setNamespace when the session is created. Is this the reason why the indexes without URI are used?
    Any other performance improvement hints?
    Thanks,
    Ken

  • Crosstab with multiple rowset xml content

    I have multiple rowsets (xml files) which I want to calculate subtotals from.  Each xml data set has identical columns.  If I union all the files together, the xml content contains multiple rowsets and the Crosstab function does not give me a summed value of each column, but instead it creates a column for each column in each rowset.
    The Normalize and the rowset combiner transform both combine rowsets by appending the second dataset into new columns, is there any way to append the data into new rows instead?
    Because my final file is going to have something over 30,000 rows (14Mb), I am reluctant to use a repeater on each row of each file to combine it into a new rowset.  Is there an efficient way to handle this calculation?

    Sue,
    I believe that we are off on the wrong foot here...all things aside...
    Join will work for your scenario when combined with other actions for your calculation and it will be easier to maintain than a stylesheet which will be beneficial to you in the end.  Please do not be too quick to judge the solution
    As for the error message that's one for support, what was the error in the logs?
    -Sam

  • Converting xml file with arabic content to pdf using FOP

    Hello all
    I am trying to convert a dynamically generated xml file in which most of the data comes from the oracle database with arabic content, to pdf using FOP. I have used "Windows-1256" encoding for the xml. If i open the xml generated with the internet explorer the arabic content displays properly but the pdf is not generated and the acrobat reader shows the file as corrupted or not supported. Please help me. Its very urgent.
    Thanks & Regards
    Gurpreet Singh

    There is no direct support for importing RTF from an XML extract. Perhaps feature 1514 "Mapping formatted XML data into multiline field" will be of some use. This was released in 11.0, I believe.
    Essentially you can establish paragraph and certain text formatting like bold and underline when you include the proper token information in the data. I believe this is similar to simple HTML tokens.
    Example: &lt;FIELD>&lt;P>First paragraph of data.&lt;/P>&lt;P>New paragraph with &lt;B>&lt;U>bold and underline text&lt;/U>&lt;/B>. Rest of paragraph normal.&lt;/P>&lt;/FIELD>
    The result is something like this:
    <P>First paragraph of data.</P><P>New paragraph with <B><U>bold and underline text</U></B>. Rest of paragraph normal.</P>

  • Problem with displaying XML Content well formatted.

    Hi all,
    I am developing a website which have one functionality to display XML content which is received from some other party.
    I am using TextArea for displaying this XML content on my webpage. As this XML content is not at all formatted it looks very ugly for a human to read.
    I want this XML content to be displayed well formatted, As Mozilla Firefox display it hierarchically and well formatted.
    Kindly give some suggestion for displaying XML well formatted on a webpage.
    Any comments from you people will help me.
    Thanks
    typurohit.

    The following link is a XML-based document. An XSL stylesheet transforms the XML document to HTML in the web browser. Feel free to grab a copy of the stylesheet to use as a guide.
    http://www.masonicartbook.com/production.htm
    Good luck!

  • Adf Input Text with formatted xml Content

    Hi,
    I have a requirements where I get an xml content in one line
    as suppose <xml ><a><a1></a1><a2><a2></a><b></b></xml>
    I want this Input text to render it proper fromat like
    <xml >
        <a>
            <a1>
            </a1>
             <a2>
             <a2>
       </a>
       <b>
      </b>
    </xml>I tried to set wrap property to soft
    but it is not affecting
    Please tell me any component that will properly structure the input xml
    How can I do this.

    User, please tell us your jdev version!
    There is no component AFAIK. You may want to try the rich text editor, but if I remember it correct it won't do what you want.
    My solution would be to write a custom converter and format the code in the converter to show it then in the inputText.
    Timo

Maybe you are looking for

  • Can I use dynamic alias to name a column?

    I guys. I just want to know if it is possible to assign dynamic names to a column. for instance: SQL> select sysdate+1 from dual; SYSDATE+1 09-JUL-08the column name is SYSDATE+1. can I do something like: SQL> select 1 as (select sysdate from dual) fr

  • Setting php 5 as default php on tiger.

    I am trying to set up symfony on Tiger and I am running into a problem. Symfony requires php 5 to be installed not only for the web server but as the system php interpreter. How can I set teh entropy.ch php 5 package as teh default system php in tige

  • Hello.aef script no errors but doesnt give any info

    Hi there, I created the two web pages and put them in the appropriate directories and can see them in a web browser.I created a trigger.  I uploaded the second greeting.html  to the document management section in the web admin as well. I type in a na

  • How to find 99 cent movie rentals in Australia

    How do I find the 99 cent iTunes movie rentals in Australia ?

  • Two teamed Gbe nics not transferring files at 2Gbps speeds

    We are doing some testing with nic teaming to increase network throughput between servers.  We have two servers (Dell r815) with windows server 2012.  They are directly connected via two cat-6 straight-through cables, with teamed nics.  The teams use