This solution has nothing to do with xml, just create your own Reader or stream
class, and before returning the real data, return the "<Root>" string. When all
the real data is exhausted, return </Root>

here's some pseudo code, haven't tried it just typing it in to email.

you'd probably have to handle reading arrays as well.

It would probably be easier to use Readers as well.

class RootNodeStream extends FilterStream
{
    private InputStream is;
    private static byte[] PREAMBLE = "<root>".getBytes("UTF-8");
    private static byte[] POSTAMBLE = "</root>".getBytes("UTF-8");

    private boolean state = BEFORE;
    private int charPos = 0;

    public RootNodeStream(InputStream s)
    {
        is = s;
    }

    public int read()
    {
        if (state == BEFORE)
        {
           byte b =PREAMBLE[charPos++];
           if (charPos >= PREAMBLE.length)
               state = IN;
           return b;
        }

        if (state == IN)
        {
            byte b = in.read();
            if (b == -1)
            {
                state = AFTER;
                charPos = 0;
            }
            else
                return b; 
        }
                       
        if (state == AFTER)
        {
           byte b =POSTAMBLE[charPos++];
           if (charPos >= POSTAMBLE.length)
               state = DONE;
           else
               return b;
        }

        return -1;
    }
}


Quoting Sogol G <[EMAIL PROTECTED]>:

> Hi, I'm new to Xerces and I'm not sure how I should
> exactly do that.  Can you please give me a litttle
> code snippet to get me started?
> 
> Thanks a lot..
> 
> --- [EMAIL PROTECTED] wrote:
> 
> > Perhaps create your own stream class that prefixes
> > and postfixes a valid root,
> > and pass that to the parser.
> > 
> > Quoting Sogol G <[EMAIL PROTECTED]>:
> > 
> > > Hello,
> > > 
> > > I have an XML document that's not well-formed. 
> > It's
> > > missing its root element.  The rest of it is
> > > well-formed.
> > > 
> > > EX: it's like this:
> > > <blah attr='val'/>
> > > <blah attr2='val2'/>
> > > <blah attr3='val2'/>
> > > .
> > > .
> > > 
> > > 
> > > I need to parse this document using Xerces.  I
> > have a
> > > few ideas of how I should do this, but I wanted to
> > > also ask you guys to see if there are easier
> > methods
> > > of doing this.  A small code snippet to clarify
> > your
> > > suggestion would be appreciated.  
> > > 
> > > Thanks,
> > >  Sogol
> > > 
> > > __________________________________________________
> > > Do You Yahoo!?
> > > Tired of spam?  Yahoo! Mail has the best spam
> > protection around 
> > > http://mail.yahoo.com 
> > > 
> > >
> >
> ---------------------------------------------------------------------
> > > To unsubscribe, e-mail:
> > [EMAIL PROTECTED]
> > > For additional commands, e-mail:
> > [EMAIL PROTECTED]
> > > 
> > 
> > 
> > 
> > 
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> > [EMAIL PROTECTED]
> > For additional commands, e-mail:
> > [EMAIL PROTECTED]
> > 
> > 
> 
> 
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around 
> http://mail.yahoo.com 
> 




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to