473,898 Members | 2,944 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XML in a Textbox

Hi,
I have an xml doc in a string it all just runs to gether no crlf or
indents, I want to lay it out in a textbox so each element is on its
ownline and indented correctly.

how do I do this

vb dotnet

thanks
Nov 21 '05 #1
3 6567
July 22, 2005

Check into XML Readers and scroll through the elements and outputing them
gradually into the text box.... it is going to be a lot of work...

--
Joseph Bittman
Microsoft Certified Application Developer

Web Site: http://71.39.42.23
Static IP


"Adrian" <ad****@nospam. comk> wrote in message
news:db******** **@nwrdmz01.dmz .ncs.ea.ibs-infra.bt.com...
Hi,
I have an xml doc in a string it all just runs to gether no crlf or
indents, I want to lay it out in a textbox so each element is on its
ownline and indented correctly.

how do I do this

vb dotnet

thanks

Nov 21 '05 #2
> I have an xml doc in a string it all just runs to gether no crlf or
indents, I want to lay it out in a textbox so each element is on its
ownline and indented correctly.

The following routine creates a string from an XML document with all
the formatting characters (crlf, tab et al.) in place.

Good News: It gives a nicely formatted output for my textbox
Bad news: There a few strangenesses with it that I haven't tracked down
yet and might cause problems (or they might not)
The basic idea is to use an XMLTextWriter to write to a MemoryStream
and then read the contents of the memStream into a string.
Private Function PrettyPrintXML( ByVal xmlDoc As XmlDocument) As
String

Dim ret As String = String.Empty

Dim memStream As New MemoryStream
Dim writer As XmlTextWriter
Dim reader As StreamReader

Try

writer = New XmlTextWriter(m emStream,
System.Text.Enc oding.UTF8)

writer.Formatti ng = Formatting.Inde nted
writer.Indentat ion = 3
xmlDoc.WriteTo( writer)
writer.Flush()

' NOTE1 : We can't close the writer here as this will close
the memstream

'ret =
System.Text.Enc oding.UTF8.GetS tring(memStream .GetBuffer())

'NOTE2: This looks like it should work but gives me extra
characters at the start of the
' string. (1st 3 chars of the memstream are not
obviously part of the XML output.

memStream.Seek( 0, SeekOrigin.Begi n)
reader = New StreamReader(me mStream)
ret = reader.ReadToEn d
Finally

'NOTE3: As both the reader and writer are pointing to the
memstream and both
' try to close the memstream when they are
closed we cannot close both
' No idea if this will cause an error or not.

reader.Close()

End Try

Return ret

End Function
If anyone can come up with a better way (or tweaks on this code) I
would be interested.

Thanks
Alan.

Nov 21 '05 #3
Hi Allan
thanks for the approach and code sample re the 1st and third char not be
correct I either don't understand this or its not a problem on the XML I'm
looking at...

It work great :)

Thanks
<al*******@user s.com> wrote in message
news:11******** *************@g 43g2000cwa.goog legroups.com...
I have an xml doc in a string it all just runs to gether no crlf or
indents, I want to lay it out in a textbox so each element is on its
ownline and indented correctly.

The following routine creates a string from an XML document with all
the formatting characters (crlf, tab et al.) in place.

Good News: It gives a nicely formatted output for my textbox
Bad news: There a few strangenesses with it that I haven't tracked down
yet and might cause problems (or they might not)
The basic idea is to use an XMLTextWriter to write to a MemoryStream
and then read the contents of the memStream into a string.
Private Function PrettyPrintXML( ByVal xmlDoc As XmlDocument) As
String

Dim ret As String = String.Empty

Dim memStream As New MemoryStream
Dim writer As XmlTextWriter
Dim reader As StreamReader

Try

writer = New XmlTextWriter(m emStream,
System.Text.Enc oding.UTF8)

writer.Formatti ng = Formatting.Inde nted
writer.Indentat ion = 3
xmlDoc.WriteTo( writer)
writer.Flush()

' NOTE1 : We can't close the writer here as this will close
the memstream

'ret =
System.Text.Enc oding.UTF8.GetS tring(memStream .GetBuffer())

'NOTE2: This looks like it should work but gives me extra
characters at the start of the
' string. (1st 3 chars of the memstream are not
obviously part of the XML output.

memStream.Seek( 0, SeekOrigin.Begi n)
reader = New StreamReader(me mStream)
ret = reader.ReadToEn d
Finally

'NOTE3: As both the reader and writer are pointing to the
memstream and both
' try to close the memstream when they are
closed we cannot close both
' No idea if this will cause an error or not.

reader.Close()

End Try

Return ret

End Function
If anyone can come up with a better way (or tweaks on this code) I
would be interested.

Thanks
Alan.

Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2142
by: Jonas L | last post by:
Hi, I need to create a textbox which acts as a normal textbox but with the following extra requirements: 1) In-focus color, when the textbox gets focus the backcolor property of the textbox should be set to a, selectable, in-focus color. 2) Out-of-focus color, when the textbox loses focus the backcolor property of the textbox should be set to a, selectable, out-of-focus color.
4
2936
by: Rodrigo DeJuana | last post by:
Howdy, I'm new to this .net stuff and really have little to no training. Im trying to create a new page for a web form, so i have been pretty much jsut coping code. I having some issue with some textboxes not updating when i a hit save. for example I have this code in my aspx.cs file: declared:
0
1848
by: Newasps | last post by:
Hi guys, I have a problem with UpdateCommand Event. In tihs event Ä°'m creating required controls to get that controls' values and also get them. But when I try to get updated values I'm getting the first values for each control. Please help me. Thanks for any help. Bye Ozer And here's my code: Imports System Imports System.Data Imports System.Data.OleDb
7
2148
by: I am Sam | last post by:
I have a DataGrid that is passing information to a stored procedure properly but the parameters aren't being casted properly. I was woundering if anyone can tell me how I should properly cast the following: (TextBox)UserPrefix=(TextBox)e.Item.Cells.Controls; string strUserPrefix=UserPrefix.Text; I keep getting the following error and I don't know why because I have declared the UserPrefix as a textbox using "protected...
11
4589
by: Keith | last post by:
I apologize for those of you who think I'm posting on the same topic. It is not that I don't appreciate all of your comments - and I'm definitely reading them all - but I think I have a differing opinion of how I want to handle the 'user experience' in the application I'm creating. While I know I could allow the user to enter in number and alpha text - in a text box - and then tell them when the execuate a command "This is not numeric data", I...
2
19890
by: Mamatha | last post by:
Hi I want to add an icon to the textbox's text. I don't know how to display icon in textbox in VB.NET. If any one knows please let me know. Thanks in advance. Mamatha
3
2238
by: Brad Rogers | last post by:
All, Being immersed in vb.net and trying CSharp after almost a year I forgot the differences. I like vb fixing the uppercase/lowercase names and seeming to be more flexible to code entry. But while trying to insert a text box to see when a method is used, and putting a counter to bump some variable? The textbox sits there unchanged. I put a breakpoint at the text write
0
2408
by: Jacob Donajkowski | last post by:
Once the user logs in I want to have the users switch from the Roster View to the Profile View and enter their profile infomation and save it. Then the next time they login and go to the Profile View I want the form populated from there profile on the sql server. The code to save the profile works fine. But when the user logs back in they data doesn't load back to the form. The multiview is located inside the LoginView's Logged-In View ....
8
36910
by: Marco Pais | last post by:
Hi there. How can I change the background color of a textbox when it gets the focus? I can handle the "Enter" event and do this private void txtDummie_Enter(object sender, EventArgs e) { txtDummie.BackColor=Color.Red; }
1
1647
by: Andy B | last post by:
I have this code: protected void EditEventsWizard_NextButtonClick(object sender, WizardNavigationEventArgs e) { //get the values from the DetailsView TextBox StartTime = (TextBox)EditEventForm.Rows.Cells.Controls; TextBox EndTime = (TextBox)EditEventForm.Rows.Cells.Controls;
0
9993
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10858
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10948
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10484
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9662
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7187
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5881
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
4296
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3305
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.