[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Conversion XML into Byte array

Posted on 2006-05-07
16
Medium Priority
?
2,772 Views
Last Modified: 2013-11-19
I need to "send up" a complex XML structure to a SOAP request.

The XML itself may have a couple of dozen tags nested a couple of levels deep.  It may even have a tag with bin64 encoded data (depends on the request).

I've seen code for reading a file into a Byte array and sending that to a server (in XML), but I've never seen code for converting XML into the same.  I'm looking for how to do this so I can make this soap request.
0
Comment
Question by:Gene Klamerus
  • 10
  • 5
16 Comments
 
LVL 9

Expert Comment

by:Naveen Swamy
ID: 16628092
Dim memStre as MemoryStream = new MemoryStream(InternalGetDocument(name))

or to get the Document ...

public function GetDocument(byval name as string) as byte ()
      return InternalGetDocument(name)
end function

this might also help you

http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/VB_DOT_NET/Q_21726205.html
http://www.experts-exchange.com/Web/Web_Languages/XML/Q_20796127.html
http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/Q_20911498.html
http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/Q_21404956.html
0
 
LVL 1

Author Comment

by:Gene Klamerus
ID: 16633461
This links are nice, but they mostly refer to creating binary XML elements, which we do already know.

The function MemoryStream looks interesting, but I don't see where InternalGetDocument() is documented anywhere.  I see that it may be a JavaScripting function, but we're using VB.Net (hence the question being in this forrum).

Let me clarify that my starting point is having a DOM in memory in a VB.Net application (or scripting in an ASP/ASPX).  I need to submit that as a SOAP request to the service (a SOAP service), as a single argument.

What I haven't seen anywhere is how to convert the DOM into a byte array or string (which we can easily convert between).
0
 
LVL 1

Author Comment

by:Gene Klamerus
ID: 16633524
I've tried to make a more complete and thorough full description for this query.  This follows:

I need to "send up" a complex XML structure to a SOAP request from a VB.Net program.  It's also possible that we may need to do this from ASPX.

Either way, the program or page is the client to the server that we have and to which we need to upload the data.

The XML itself may have a couple of dozen tags nested a couple of levels deep.  It may even have a tag with bin64 encoded data (depends on the request).  We know how to create all this.

What we have had a struggling doing is finding out how to submit this to a web service (SOAP), but very recently someone suggested turning it into a byte array or string and sending it up as a single parameter.

This requires turning the XML structure into a byte array or string and returning it to an XML structure on the server.  We will do this in memory in a DOM.  We don't want to create a file just to upload.  That will have a performance impact.  We want to do this directly from the DOM structure in memory.

I've seen code for reading a file into a Byte array and sending that to a server (in XML), but I've never seen code for converting XML structure in a DOM in memory into a byte array or string.

I'm looking for how to do this so I can make this soap request.

Conversely I'd be interested in superior alternatives to this approach, but only something standard or very wide-spread (not DIME or WS-Attachment).
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 96

Expert Comment

by:Bob Learned
ID: 16635929
1) Base-64 encoding:  

   Dim buffer() As Byte = Convert.FromBase64String(str)
   Dim str As String = Convert.ToBase64String(buffer)

2) Encoding:

   Dim buffer() As Byte = System.Text.Encoding.Utf8.GetBytes(str)
   Dim str As String = System.Text.Encoding.Utf8.GetString(buffer)

Bob
0
 
LVL 1

Author Comment

by:Gene Klamerus
ID: 16638099
I just said I know how to convert between strings and byte arrays.  What I need is to convert from an in-memory DOM into either one or the other.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 16639018
Words, words, words.  It is easy with all those words to miss something ;)

What do you mean by "convert from an in-memory DOM into either one or the other"?

Bob
0
 
LVL 1

Author Comment

by:Gene Klamerus
ID: 16644223
I'm not sure how much more clearly to say it.  We all (I expect) create in memory XML structures.  DOM (Document Object Model) is one, but any XML structure will do.

An example of the XML structure I need to deal with follows.  I need to convert that (when in memory in an XML structure) into a string or byte array so that I can upload it via SOAP.

<?xml version="1.0"?>

<!DOCTYPE omdv-msg SYSTEM "omdv-msg-3_0.dtd">

<omdv-msg>

      <message-spec sender="ECOA-WEB-GLOBAL" correl-id="CERT_02885634.PDF" priority="PREMIUM" notify-type="ALL" notify-platform="NO">
            <status/>
            <status-text/>
            <beg-ts>30-Apr-2006 at 04:11:11 AM</beg-ts>
            <end-ts/>
            
            <sender-sig/>
            <notify-at>u383534</notify-at>
            <message-digest/>
            <current-service>1</current-service>
            <delegate-mailbox>FTNECOA</delegate-mailbox>
      </message-spec>
      
      <service-spec srvc-order="1" srvc-type="ARCHIVE" srvc-complete="NO" upon-failure="ABORT" notify-platform="NO" full-hdr="NO">
            <status/>
            <status-text/>
            <beg-ts/>
            <end-ts/>
            
            <archive-action>READ</archive-action>
            <docbase>ECOA01</docbase>
            <document-type>certificate_analysis</document-type>
            <select-attrib NAME="r_object_id">09002f188060a568</select-attrib>
      </service-spec>
      
      <service-spec srvc-order="2" srvc-type="FILTER" srvc-complete="NO" upon-failure="ABORT" notify-platform="NO" full-hdr="NO">      
            <status/>
            <status-text/>
            <beg-ts/>
            <end-ts/>

            <rem-log>NO</rem-log>
            <rem-water>NO</rem-water>
            <output-format ENCODING="PDF" PAPER-SIDES="SINGLE-SIDED" PAPER-SIZE="LETTER"></output-format>
      </service-spec>
      
      <service-spec srvc-order="3" srvc-type="EMAIL" srvc-complete="NO" upon-failure="CONTINUE" notify-platform="NO" full-hdr="NO">      
            <status/>
            <status-text/>
            <beg-ts/>
            <end-ts/>
            
            <reply-to>u383534</reply-to>
            <cover-block>ECOA/  HKYANGZI 2005-35/ NP-10</cover-block>
            <attachment-name>CERT_02885634.PDF</attachment-name>
            <to-addrs>lhou@dow.com</to-addrs>
      </service-spec>
      
      <service-spec srvc-order="4" srvc-type="ARCHIVE" srvc-complete="NO" fail-type="FAIL-CONTINUE" notify-platform="NO" full-hdr="NO">      
            <status/>
            <status-text/>
            <beg-ts/>
            <end-ts/>
            
            <archive-action>UPDATE</archive-action>
            <docbase>ECOA01</docbase>
            <document-type>certificate_analysis</document-type>
            <select-attrib NAME="r_object_id">09002f188060a568</select-attrib>
      </service-spec>

<payload>
Admin Allow v1.0 Jan 14, 1997 (public domain, no warranty!)
By Mike Ingle (inglem@adnetsol.com,inglem@std.teradyne.com)

Frequently NT administrators have files and directories that do not
allow Administrator access. This creates a problem for virus scans,
moving directories, user support, etc. Taking ownership is time-
consuming and breaks existing permissions.

This program modifies file permissions on NTFS files and directories
to allow Full Control for Administrators without breaking existing
permissions or taking ownership. Run it like:

admnalow d: e:
Affects all of D: and E: drives.
admnalow e:\users\joe
Affects only one directory (or file) and all subdirectories.

While running, the program prints a list of all files and directories
it has altered. It will also print any errors. It does not change files
that are already set correctly, so it will not turn your daily backup
into a total.

You can run this nightly before a virus scan or other automatic
operation from the scheduler, or run it as needed. It needs
administrator access, take-ownership, backup, and restore privileges.

How this program works:

The program turns on take-ownership, backup, and restore privileges.
Then it uses a findfirst/findnext loop to traverse the directories.
For each file or directory, it reads and inspects the ACL. If the ACL
does not give full control to administrators, or if it can't read the
ACL, it changes permissions on that file.

To do this, it first uses BackupRead to get the old owner of the file.
There is no politically correct way to do this without access to the
file that I know of, but the owner SID appears to be in a fixed location
in the data from BackupRead. In any case, the program checks the SID
and won't touch a file if it can't validate the SID.

Having read the old owner, it then sets owner to Administrator. It reads
the ACL, copies all ACEs not referring to Administrator to a new ACL,
and then adds ACEs giving administrator full control. Then it writes the
new ACL and sets the owner back as it found it. This leaves the file
permissions unchanged except for administrators having access.
</payload>

</omdv-msg>
0
 
LVL 1

Author Comment

by:Gene Klamerus
ID: 16644231
Sometimes the payload portion of these XML structures will include a bin64 encoded PDF document, or word document, or image, etc.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 16647603
1) Now that I understand the file structure, I need to fully understand the process, because I feel like I am missing an important piece.

2) Are you looking to serialize the entire XML document for a SOAP request?

3) Are you looking to extract parts of the document?

Bob
0
 
LVL 1

Author Comment

by:Gene Klamerus
ID: 16648694
I'm looking to turn the entire thing into a byte array (which I have an example of submitting as a SOAP request).

If there's a different way of doing this (other than the byte array) I'm good with that.  The need is to upload this data as a SOAP request one way or another.
0
 
LVL 1

Author Comment

by:Gene Klamerus
ID: 16648850
It looks like the following may work for me:

        Dim XmlDoc As New XmlDocument

        XmlDoc.Load("C:\Temp\Test1.xml")

        Dim TestText As System.String = XmlDoc.OuterXml

        RichTextBox1.Text = TestText

Or something like this.  I'm still working on it.
0
 
LVL 1

Author Comment

by:Gene Klamerus
ID: 16648855
The loading was just to get me an XML in memory.  In reality, we're going to get the data from WebSphere MQ.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 16649053
If you are just loading string text from a document, you don't need to use XmlDocument, you could just use a StreamReader or even RichTextBox.LoadFile.  I was struggling to understand what you meant.  I didn't realize that you were looking for something that simple.

Bob
0
 
LVL 1

Author Comment

by:Gene Klamerus
ID: 16654265
As I said (somewhere), I'm currently loading the XML from a file to get the code working.  The data will be coming from a websphere MQ message.

What I need to do with it though is upload it to a web service.  So far as I know the code on the client (VB.Net) needs to match the code on the server (also VB.Net) both in number and type of parameter when doing ASP.Net web services (which I am).

I've heard that a byte array can be sent up because it will be a single parameter.  I just need to generate the byte array and interpret it at both ends.   On the client end, what I'll have is an XML structure (in memory) to start with.  That's also what I'll need to end up with on the server eventually.
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 1500 total points
ID: 16657218
Well, if you know how to read XML text, and how to convert strings to byte arrays, then what is your question?

Bob
0
 
LVL 1

Author Comment

by:Gene Klamerus
ID: 16664080
I didn't know all of that when I posted this question (3-4 days ago).
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL several years ago, it seemed like now was a good time to update it for object-oriented PHP.  This article does that, replacing as much as possible the pr…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
Suggested Courses

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question