Hi everyone,
I'm having problems with Tab characters in an XML file.
I want to store a Tab character as part of an element value e.g.
<Separator>TA B</Separator>
I'm using XmlWriter to write my file and XmlReader to read it.
At first my tab character was stored in the element, but was ignored
when it was read back (giving me an empty string as a content).
Herfried K. Wagner suggested on this group to use the
'xml:space="pre serve"' attribute. It worked fine, except that now I
have to generate my whole file without indentation otherwise the
reader generates an exception.
Ideally I would like
1) To be able to store Tab characters in an element value
2) Have an indented XML file e.g.
<Config>
<Some Container Element>
<Separator>TA B</Separator>
</Some Container Element>
<Some Other Element>
</Some Other Element>
<Config>
I've tried to play with the values of the XmlReader and XmlWriter
settings, but can only manage to get either 1) or 2) but not both at
the same time.
Can somebody help me with that?
Thanks
JB 7 3657
JB,
Probably you need an &arg litteral. I don't know which it is, but as I have
to do it as well can you search for it on Internet yourself.
Cor
"JB" <jb*********@gm ail.comschreef in bericht
news:36******** *************** ***********@d77 g2000hsb.google groups.com...
Hi everyone,
I'm having problems with Tab characters in an XML file.
I want to store a Tab character as part of an element value e.g.
<Separator>TA B</Separator>
I'm using XmlWriter to write my file and XmlReader to read it.
At first my tab character was stored in the element, but was ignored
when it was read back (giving me an empty string as a content).
Herfried K. Wagner suggested on this group to use the
'xml:space="pre serve"' attribute. It worked fine, except that now I
have to generate my whole file without indentation otherwise the
reader generates an exception.
Ideally I would like
1) To be able to store Tab characters in an element value
2) Have an indented XML file e.g.
<Config>
<Some Container Element>
<Separator>TA B</Separator>
</Some Container Element>
<Some Other Element>
</Some Other Element>
<Config>
I've tried to play with the values of the XmlReader and XmlWriter
settings, but can only manage to get either 1) or 2) but not both at
the same time.
Can somebody help me with that?
Thanks
JB
Duh,
did not read the message from Stephany yet, it is of course &
Cor
"Cor Ligthert[MVP]" <no************ @planet.nlschre ef in bericht
news:A7******** *************** ***********@mic rosoft.com...
JB,
Probably you need an &arg litteral. I don't know which it is, but as I
have to do it as well can you search for it on Internet yourself.
Cor
"JB" <jb*********@gm ail.comschreef in bericht
news:36******** *************** ***********@d77 g2000hsb.google groups.com...
>Hi everyone,
I'm having problems with Tab characters in an XML file. I want to store a Tab character as part of an element value e.g. <Separator>TAB </Separator> I'm using XmlWriter to write my file and XmlReader to read it.
At first my tab character was stored in the element, but was ignored when it was read back (giving me an empty string as a content). Herfried K. Wagner suggested on this group to use the 'xml:space="pr eserve"' attribute. It worked fine, except that now I have to generate my whole file without indentation otherwise the reader generates an exception.
Ideally I would like 1) To be able to store Tab characters in an element value 2) Have an indented XML file e.g.
<Config> <Some Container Element> <Separator>TAB </Separator> </Some Container Element> <Some Other Element> </Some Other Element> <Config>
I've tried to play with the values of the XmlReader and XmlWriter settings, but can only manage to get either 1) or 2) but not both at the same time.
Can somebody help me with that?
Thanks JB
No Cor, it is NOT &. It IS &.
The semi-colon is not for decoration, it is critical.
Any, if you're talking about a TAB character, there is no way it is &.
It would be 	.
& = escape character
# = numeric literal
x = hexadecimal
9 = ASCII (also ANSI) for TAB character
; = escape sequence terminator
"Cor Ligthert[MVP]" <no************ @planet.nlwrote in message
news:5C******** *************** ***********@mic rosoft.com...
Duh,
did not read the message from Stephany yet, it is of course &
Cor
"Cor Ligthert[MVP]" <no************ @planet.nlschre ef in bericht
news:A7******** *************** ***********@mic rosoft.com...
>JB,
Probably you need an &arg litteral. I don't know which it is, but as I have to do it as well can you search for it on Internet yourself.
Cor
"JB" <jb*********@gm ail.comschreef in bericht news:36******* *************** ************@d7 7g2000hsb.googl egroups.com...
>>Hi everyone,
I'm having problems with Tab characters in an XML file. I want to store a Tab character as part of an element value e.g. <Separator>TA B</Separator> I'm using XmlWriter to write my file and XmlReader to read it.
At first my tab character was stored in the element, but was ignored when it was read back (giving me an empty string as a content). Herfried K. Wagner suggested on this group to use the 'xml:space="p reserve"' attribute. It worked fine, except that now I have to generate my whole file without indentation otherwise the reader generates an exception.
Ideally I would like 1) To be able to store Tab characters in an element value 2) Have an indented XML file e.g.
<Config> <Some Container Element> <Separator>TA B</Separator> </Some Container Element> <Some Other Element> </Some Other Element> <Config>
I've tried to play with the values of the XmlReader and XmlWriter settings, but can only manage to get either 1) or 2) but not both at the same time.
Can somebody help me with that?
Thanks JB
JB wrote:
I'm having problems with Tab characters in an XML file.
I want to store a Tab character as part of an element value e.g.
<Separator>TA B</Separator>
I'm using XmlWriter to write my file and XmlReader to read it.
At first my tab character was stored in the element, but was ignored
when it was read back (giving me an empty string as a content).
Can you show us your code? I can't reproduce the problem, the following
test code
Dim fileName As String = "..\..\XmlTest1 .xml"
Dim writerSettings As New XmlWriterSettin gs()
writerSettings. Indent = True
Using writer As XmlWriter = XmlWriter.Creat e(fileName,
writerSettings)
writer.WriteSta rtDocument()
writer.WriteSta rtElement("root ")
writer.WriteSta rtElement("foo" )
writer.WriteEle mentString("bar ", ChrW(9).ToStrin g())
writer.WriteEnd Document()
End Using
Using reader As XmlReader = XmlReader.Creat e(fileName)
While reader.Read()
If reader.NodeType = XmlNodeType.Ele ment And
reader.LocalNam e = "bar" Then
Dim bar As String = reader.ReadStri ng()
Console.WriteLi ne("|{0}|", bar)
Console.WriteLi ne(bar = ChrW(9).ToStrin g())
End If
End While
End Using
results in the output
| |
True
suggesting that the tab character is written and read back.
Make sure you don't use an XmlReader with XmlReaderSettin gs where
IgnoreWhitespac e is set to True as in that case the tab would be ignored.
--
Martin Honnen --- MVP XML http://JavaScript.FAQTs.com/
On 15 Jun, 15:09, Martin Honnen <mahotr...@yaho o.dewrote:
JB wrote:
I'm having problems with Tab characters in an XML file.
I want to store a Tab character as part of an element value e.g.
<Separator>TA B</Separator>
I'm using XmlWriter to write my file and XmlReader to read it.
At first my tab character was stored in the element, but was ignored
when it was read back (giving me an empty string as a content).
Can you show us your code? I can't reproduce the problem, the following
test code
Dim fileName As String = "..\..\XmlTest1 .xml"
Dim writerSettings As New XmlWriterSettin gs()
writerSettings. Indent = True
Using writer As XmlWriter = XmlWriter.Creat e(fileName,
writerSettings)
writer.WriteSta rtDocument()
writer.WriteSta rtElement("root ")
writer.WriteSta rtElement("foo" )
writer.WriteEle mentString("bar ", ChrW(9).ToStrin g())
writer.WriteEnd Document()
End Using
Using reader As XmlReader = XmlReader.Creat e(fileName)
While reader.Read()
If reader.NodeType = XmlNodeType.Ele ment And
reader.LocalNam e = "bar" Then
Dim bar As String = reader.ReadStri ng()
Console.WriteLi ne("|{0}|", bar)
Console.WriteLi ne(bar = ChrW(9).ToStrin g())
End If
End While
End Using
results in the output
| |
True
suggesting that the tab character is written and read back.
Make sure you don't use an XmlReader with XmlReaderSettin gs where
IgnoreWhitespac e is set to True as in that case the tab would be ignored.
--
Martin Honnen --- MVP XML http://JavaScript.FAQTs.com/
Hi All,
Thanks for all your suggestions.
Following Martin's code I isolated the problem.
I read my file sequentially and I use the function
ReadElementCont entAsString.
If I write the file without indentation, ReadElementCont entAsString
works fine.
If I write the file with indentation, ReadElementCont entAsString
causes an exception: "'Whitespac e' is an invalid XmlNodeType. Line 3,
position 8."
I don't really want to have to rewrite all my code to look like Method
2, so I'm thinking that it might be simpler to escape all my string
contents to transform any special character into the escaped version.
Is there an option to do this automatically for my entire XML file or
do I have to do it "manually" for each field with some sort of
replace?
See my code below:
Using reader As XmlReader = XmlReader.Creat e(fileName)
reader.ReadStar tElement("root" )
reader.ReadStar tElement("foo")
'Method 1 - Doesn't work
' Dim bar As String = reader.ReadElem entContentAsStr ing("bar",
"")
'Method 2 - Works!
reader.Read()
Debug.Assert(re ader.NodeType = XmlNodeType.Ele ment And
reader.LocalNam e = "bar")
Dim bar As String = reader.ReadStri ng()
Console.WriteLi ne("|{0}|", bar)
Console.WriteLi ne(bar = ChrW(9).ToStrin g())
reader.ReadEndE lement()
reader.ReadEndE lement()
End Using
JB wrote:
Following Martin's code I isolated the problem.
I read my file sequentially and I use the function
ReadElementCont entAsString.
If I write the file without indentation, ReadElementCont entAsString
works fine.
If I write the file with indentation, ReadElementCont entAsString
causes an exception: "'Whitespac e' is an invalid XmlNodeType. Line 3,
position 8."
Well that exception has nothing to do with the 'bar' element containing
a tab character or not. It occurs because
reader.ReadStar tElement("foo")
after this call the reader is positioned on a node of type Whitespace
and therefore ReadElementCont entAsString() is not an allowed operation.
For that to work you first have to make sure the reader is positioned on
the start element.
--
Martin Honnen --- MVP XML http://JavaScript.FAQTs.com/
JB wrote:
Thanks for all your suggestions.
Following Martin's code I isolated the problem.
I read my file sequentially and I use the function
ReadElementCont entAsString.
If I write the file without indentation, ReadElementCont entAsString
works fine.
If I write the file with indentation, ReadElementCont entAsString
causes an exception: "'Whitespac e' is an invalid XmlNodeType. Line 3,
position 8."
If you want to use the XmlReader in a way symmetric to the XmlWriter use
I suggested then you can use
reader.ReadStar tElement("root" )
reader.ReadStar tElement("foo")
Dim bar As String = reader.ReadElem entString("bar" )
--
Martin Honnen --- MVP XML http://JavaScript.FAQTs.com/ This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Roy W. Andersen |
last post by:
I've been searching google about this for days but can't find anything,
so I'm hoping someone here can help me out.
I'm trying to create zip-files without needing the zip-file extension in
PHP, mainly because I need the ability to both create and extract
zip-files. I've tried a couple of classes found here and there, and they
all seem to have the same problem. I'm currently using PclZip
(http://phpconcept.net/pclzip/) but even the...
|
by: Stuart Newton |
last post by:
We have just migrated a pile of ASP-driven content-managed websites
from Win2000/SQL7 to Win2003/SQL2000 and noticed that, on some of
them, certain characters such as the pound sign (£), 66..99 "curly
quotes" and curly apostrophes were appearing as several characters in
the HTML output unless Internet Explorer was forced into "View ->
Encoding -> Unicode"
For example, a £ appeared as "£" and a curly apostrophe as
something with a in...
|
by: rmgalante |
last post by:
I have a Windows Service that reads and writes an XML file to disk
periodically. I use the XmlSerializer to serialize and deserialize the
XML file on disk. I am writing the file using an XmlTextWriter and UTF8
encoding.
I notice after long periods of time that my file has bad,
non-displayable characters. I try to load the XML file with IE, and it
tells me that the XML is bad for one of many different reasons,
depending on where the bad...
|
by: David Mathog |
last post by:
Every so often one of my fgets() based programs encounters
an input file containing embedded nulls. fgets is happy to
read these but the embedded nulls subsequently cause problems
elsewhere in the program. Since fgets() doesn't return
the number of characters read it is pretty tough to handle
the embedded nulls once they are in the buffer.
So two questions:
1. Why did the folks who wrote fgets() have a successful
|
by: Sakharam Phapale |
last post by:
Hi All,
I am using an API function, which takes file path as an input.
When file path contains special characters (@,#,$,%,&,^, etc), API function
gives an error as "Unable to open input file".
Same file path containing special characters works fine in one machine, but
doesn't work in other.
I am using following API function to get short file path.
Declare Auto Function GetShortPathName Lib "kernel32" (ByVal lpszLongPath As
| |
by: Frank Niessink |
last post by:
Hi list,
First of all, I wish you all a happy 2006. I have a small question that
googling didn't turn up an answer for. So hopefully you'll be kind
enough to send me in the right direction.
I'm developing a desktop application, called Task Coach, that saves its
domain objects (tasks, mostly :-) in an XML file. Users have reported
that sometimes their Task Coach file would become unreadable by Task
Coach after copying information from...
|
by: david.lindsay.green |
last post by:
Hello all, I am quite new a web scripting and making web pages in
general and I have stumbled across a problem I have as yet been unable
to solve. I am trying to take the contents of a textarea box and save
it to a file. This step is not to hard however the contents of the
textarea is mostly latex source so it contains just about every special
character you can imagine. My question is this, how do I save an exact
copy of the textarea...
|
by: joakim.hove |
last post by:
Hello,
I am having great problems writing norwegian characters æøå to file
from a python application. My (simplified) scenario is as follows:
1. I have a web form where the user can enter his name.
2. I use the cgi module module to get to the input from the user:
....
name = form.value
|
by: =?Utf-8?B?SG9seXNtb2tl?= |
last post by:
Hi there,
I am having a problem im my webservices method when trying to save a file
with latin characters to disk passed through WSE.
I have noticed that when trying to read the file name from all the latin
characters are converted ? character which is a illegal character for file
name.
If my file name is N° documento per RomÃ
|
by: adiel_g |
last post by:
I am trying to display some data that I received into a form. The
form is in english. The data is in cyrillic (russian) which uses
codepage 1251. I am trying to change the button text to russian. For
example:
cmdCancel.Text = "Îòìåíèòü"
Those are garbage characters which I dont mind if they are in that
format in the code. But when the actual button is displayed on the
screen, I want the real cyrillic (russian) characters to be
|
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...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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...
|
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,...
|
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...
|
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();...
|
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...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |