5 Replies Latest reply: Apr 15, 2008 12:18 PM by DrClap RSS

    parsing XML data

    807591
      Could someone tell me how to take the data in this XML file and put it into one big String.

      <inputFile>
      <file header></file header>
      <books>
      <book>
      <header></header>
      <lineInputList>
      <line></line>
      <line></line>
      </lineInputList>
      </book>
      <book>
      <header></header>
      <lineInputList>
      <line></line>
      <line></line>
      </lineInputList>
      </book>
      </books>
      </inputFile>

      After I am able to do that - I will need to take that String and send it to MQ (Message Que) in form of a Byte Array.
        • 1. Re: parsing XML data
          807591
          What would your "one big string" look like? This?
          "<inputFile><fileheader></fileheader><books><book><header></header><lineInputList><line></line><line></line></lineInputList></book><book><header></header><lineInputList><line></line><line></line></lineInputList></book></books></inputFile>"
          And the usual was to convert a String to a sequence of bytes is to use a specific encoding. Is that what you want? What encoding is specified?
          • 2. Re: parsing XML data
            807591
            BigLoveHandles,
            I did not ask how to put the whole XML file (including the XML tags) into a String.
            Assume that there is some XML data between these tags.
            • 3. Re: parsing XML data
              807591
              privet2008 wrote:
              BigLoveHandles,
              I did not ask how to put the whole XML file (including the XML tags) into a String.
              Assume that there is some XML data between these tags.
              Could you please post a proper example of what you mean, then?
              • 4. Re: parsing XML data
                807591
                privet2008 wrote:
                BigLoveHandles,
                I did not ask how to put the whole XML file (including the XML tags) into a String.
                Assume that there is some XML data between these tags.
                Sounded to me like that was exactly what you were asking
                • 5. Re: parsing XML data
                  DrClap
                  So this data is in a file? And you want to load it into a byte array so you can send it to MQ?

                  First of all it doesn't matter that the data is XML. You don't have to parse it in any way. And second, converting the bytes in the file to a String and then back to bytes is wasteful and may even be harmful if you don't use the right encoding. So don't do that either.

                  All you want to do is to read the contents of the file into an array of bytes. Do you still have a question about that?