Hi Michael and Klaus!
                       As stated by you there is a difference b/w Prolog and Processing Instruction:

Prolog:
            An XML document starts with a Prolog, The prolog is used to signal the beginning of the XML data, describe its character encoding method, and provide some other configuration hints to the XML parser and application.
            The prolog consists of an optional XML declaration, which can be ommitted, and the document can still be well formed.

         "In my case I want to have 2 prolog elements, one is the
                      <?xml version="1.0"
encoding="UTF-8" ?>
          and the other one is
                     
<?qbxml version="2.0" ?> "
                -----------------------------------------------------------------------

Processing Instruction:
               it's for the application processing the XML document a hint for internal document processing. its format is:
                        <? target ....  instruction ?>
                  ---------------------------------------------------------------------

           the processing instruction doesn't contain = sign, and quotes, as is required in my case, if it would have been a processing instruction it would have been
                               <?qbxml version 2.0 ?>

           but what I need is
                           <?qbxml version=" 2.0">
           so its a prolog, along with i have confirmed from the api docs of the xml receiving app, its a prolog element. Now i am preparing my XML document or generating my XML with Xerces SAX, in normal api's the parser calls the startDocument( ), startElement( ) etc. functions, but XERCES provides a reverse solution for generating XML, the programmer calls the startDocument( ), startElement( ), endElement( ) functions. here is a piece of code I wrote to do that,
          

           FileOutputStream fos = new FileOutputStream("QBXMLRequest.xml");

            //   XERCES 1 or 2 additionnal classes.
            OutputFormat of = new OutputFormat();
            of.setIndent(1);
            of.setIndenting(true);

            XMLSerializer serializer = new XMLSerializer(fos,of);
            //    SAX2.0 ContentHandler.
            ContentHandler hd = serializer.asContentHandler ();
            hd.startDocument();


            /*  Processing instruction, this produces the processing instruction
                <?qbxml version 2.0?> not what I need i.e.
                <? qbxml version="2.0"?>
which I think is a Prolog element. */
            hd.processingInstruction("qbxml version","2.0");

            .................................................

            //         attributes.
            AttributesImpl atts = new AttributesImpl();
            //         Element tag.
            hd.startElement("","","QBXML",atts);
           
            atts.clear();
            atts.addAttribute("","","onError","CDATA","stopOnError");
            hd.startElement("","","QBXMLMsgsRq",atts);

            .......................................

            hd.endElement("","","QBXMLMsgsRq");
            hd.endElement("","","QBXML");
           
            hd.endDocument();
            fos.close();
          

           can klaus and Michael help, I think enough debate till now, which method of which class should I call, there is an OutputFormat class, but I have seen its functions, couldn't be of much help.
                     any help will be appreciated. I came across this page, which was of much help in explaining how to generate, XML with SAX and XERCES.

           http://www.javazoom.net/services/newsletter/xmlgeneration.html

Regards,
Babar Abbas,
[EMAIL PROTECTED].





On 9/5/06, Michael Glavassevich <[EMAIL PROTECTED]> wrote:
"Babar Abbas" <[EMAIL PROTECTED]> wrote on 09/04/2006 04:49:37 PM:

> Hi all!
>           There is a Prolog in XML document by default,
>                               <?xml version=" 1.0" encoding="UTF-8" ?>
>           The api I have to pass my XML stream requires me to pass
> an additional Top Level Tag,
>                    <?qbxml version="2.0" ?>
>
>           so the stream starts with,
>                            <?xml version="1.0" encoding="UTF-8" ?>
>                            <?qbxml version="2.0" ?>
>                            <QBXML>
>                                     <QBXMLMsgsRq >>
>                                                  --------------------
>
>
>                                     </QBXMLMsgsRq>
>                              </QBXML>
>              as in the above stream there a 2 prolog or header
> elements, xml and qbxml. XML is created by default, but how to
> create, the next one i.e. <?qbxml version=" 2.0" ?>, with the api's
> in org.w3c.dom package, or by the help of some other xerces package.
> for example sax packages. there are method calls to create Elements,
> Processing instructions, but no method for creating the prolog or
> top level headers, starting with <? ........?>, in the Document
> class, or I couldn't find one.

Though the two <? ... ?> things look similar syntactically they are
different constructs. The first is an XML declaration [1]. The second one
is a processing instruction [2]. Klaus gave a few tips on how you can add
one to a DOM (in the previous e-mail on this thread).

> The 2nd question I had was!
>              There are so many libraries, e.g. Crimson, Xerces,
> Xalan, XMLBeans, SAX, DOM, how are these api's related or
> differentiate from one another, which api should be used where. why
> so many api's. Anyone pointing me to some articles, or tutorial, I
> will be highly obliged, as I am new to XML so wanted to have a clear
> understanding.

There are plenty of articles floating around on these subjects. If you're
looking for a starting point you could try branching out from here:
http://www-128.ibm.com/developerworks/xml/newto/.

>                I am generating XML programmatically and then sending
> the stream to another program, I am not getting it from a document,
> so which api is best for sophisticated manipulation and generation of
XML.
>
> Any body answering these questions, or any one question, I would be
> thankfull. I am waiting eagerly.
>
> Thanks and regards,
> Babar Abbas.

[1] http://www.w3.org/TR/2006/REC-xml-20060816/#NT-XMLDecl
[2] http://www.w3.org/TR/2006/REC-xml-20060816/#NT-PI

Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: [EMAIL PROTECTED]
E-mail: [EMAIL PROTECTED]

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


Reply via email to