473,799 Members | 3,638 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XML without carriage returns after nodes

I'm still feeling my way around XML parsing and have an app that uses XML
reader and works fine as long as the XML is pretty but doesn't find all the
elements when the XML is all on a single line without the carriage returns
after each element. As I understand it XMLReader uses the carriage return as
a stop for each read.

Before I start to rewrite this, I would like to know if there's a way to
deal with this with XMLReader or will using xpath or LINQ avoid this issue?

Many thanks in advance for your assistance,
Kevin
Jul 28 '08 #1
4 3386
Kevin Vogler wrote:
I'm still feeling my way around XML parsing and have an app that uses XML
reader and works fine as long as the XML is pretty but doesn't find all the
elements when the XML is all on a single line without the carriage returns
after each element. As I understand it XMLReader uses the carriage return as
a stop for each read.

Before I start to rewrite this, I would like to know if there's a way to
deal with this with XMLReader or will using xpath or LINQ avoid this issue?
XPath or LINQ to XML work on an in-memory tree model of the XML document
while XmlReader is a low-level forwards only pull parsing approach. So
you can certainly avoid some of the hassles of using XmlReader by
switching to XPath or LINQ to XML.
On the other hand it is certainly possible to process XML with XmlReader
even if it is not indented, here is an example where the same XmlReader
logic is used to process different XML strings:

foreach (string xml in new string[] { @"<root>
<foo>foo 1</foo>
</root>",
@"<root><foo>fo o 2</foo></root>" })
{
using (XmlReader reader = XmlReader.Creat e(new
StringReader(xm l)))
{
while (reader.Read())
{
if (reader.NodeTyp e == XmlNodeType.Ele ment &&
reader.LocalNam e == "foo")
{
Console.WriteLi ne("foo: {0}",
reader.ReadStri ng());
}
}
}
}
If you need further help then show us the XML you have and explain which
data you want to extract, then it is possible to help writing XmlReader
code for that.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Jul 28 '08 #2
Kevin Vogler wrote:
There are no line feeds in the file. Is this typical? Can I work with this?
Sure, why not? I did already show an example that parsed out some data
from an XML document that had no line feeds.
If you need help parsing out certain data from the XML you posted then
explain which data you are looking for.
If not will the other methods parse this?
As said, XPath or LINQ to XML work on tree models so they provide more
power and flexibility than the forwards only XmlReader model. But I am
pretty sure that XmlReader is used under the hood to build those tree
models, there is nothing that prevents XmlReader from parsing a
well-formed XML document with or without line feeds.
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Jul 28 '08 #3
Kevin Vogler wrote:
Thanks for the response.

In the XML example that i included(see below), for instance there is a
LocalName SERVICE.
When there are no line feeds in the file, my code (below) cannot find this
element but does find the Localname CARRIERACCOUNT. Can you explain where
I've gone wrong?

Thanks again for all your help,
Kevin Vogler

My code:
While (reader.Read())
Dim LName As String = reader.LocalNam e
If reader.NodeType = XmlNodeType.Ele ment Then
Select Case LName
Case "SERVICE"
SERVICE =
reader.ReadElem entContentAsStr ing
Case "CARRIERACCOUNT "
CARRIERACCOUNT =
reader.ReadElem entContentAsStr ing
End Select
End If
End While
Use ReadString() instead of ReadElementCont entAsString(). The problem
with your code above is that ReadElementCont entAsString() moves the
reader to the next node meaning it is positioned on the next start
element tag, then the While (reader.Read()) consumes that start element
and that way your loop body does never find the element.
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Jul 28 '08 #4
Martin,

Thank you very much for pointing out my error. This took care of my issue.

Thanks,
Kevin Vogler
Jul 28 '08 #5

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

Similar topics

1
13041
by: yawnmoth | last post by:
so... i'm trying to remove all carriage returns in the input i get from GET, and am trying to replace them with three dots... however, this never seems to work... i'm still getting carriage returns... here's my script... any ideas as to what's wrong?: <?php
4
7323
by: Les Juby | last post by:
Can someone please help with a suggestion as to how I can keep the formatting (carriage returns) that the user enters into a memo field and then display that later. I figured I might be able to use: 'replace carriage returns with BRs comment=Replace(comment, chr(13), "<br>") but obviously net.! The <pre> tag doesn't sem to help either as the embedded return is
2
4131
by: Andrew Chanter | last post by:
I have a VBA function that returns a string including "vbcr" (VB Carriage Return) to seperate a list into multiple rows, eg Item1 & vbcr & Item2 & vbcr & Item3 This works as planned in the immediate window, producing a list where a Carriage Return follows each item. But when I output the result into either an Access query or form, instead of carriage returns I get little square symbols between each of the items. Is anyone able to tell...
12
5622
by: Nimmy | last post by:
Hi, I have a data file and I want to remove Carriage returns. Any one has any C code/program which does this? I am working on Windows XP machine.....I don't have access to UNIX machine. But I need to send this data file to the Unix machine once I remove the carriage retunrns from my XP machine. Thanks
7
11208
by: mattrapoport | last post by:
I have a page with a div on it. The div displays a user comment. When the user logs into this page, their current comment is pulled from a db and displayed in the div. The user can edit the comment through a pop-up that contains a textarea. When the user hits OK on the pop-up, the text in the textarea is sent to a function on the main page. The function inserts the text into the div's text node. Please don't ask why I'm making this...
6
13554
by: shajias | last post by:
Hi, I am having a xml code like this <name> I am having a carriage return here. Second line with carriage return. This is the last line. </name>
2
4656
by: GregBeagle | last post by:
Windows XP I have a simple form from which I want to generate an email with the contents of the form. I use carriage returns to format the content for readability. When I test it on my computer the email generated by getURL("mailto..") is fine in my email client. Carriage returns are kept etc and shows how I want it. However when I upload it to the server and run it on the web, the carriage returns are stripped out of the text and all...
0
1550
by: markus.shure | last post by:
Hi, I'm noticed a problem testing a JAX-WS client with a WSE server. The JAX-WS client adds carriage returns to a SOAP header element that is signed. This causes the WSE server to raise an error: "The signature or decryption failed". If the carriage returns are removed, the same web service call is successful. I tried replicating the situation with a WSE client. I created a WSE client that adds a SOAP header element that contains a...
11
12606
by: evenlater | last post by:
My db allows the user to send email via CDO. The body of the email is determined in code. I have built an email form with To, CC and Subject lines and a large text box for the body of the message so the user can edit the default email message body before sending the message. But when I populate the large text box (txtBody), I can't get it to include the carriage returns. I've tried vbNewLine, vbCrLf, Chr(10) and Chr(13). I've got the...
0
9687
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
9541
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,...
0
10252
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
10231
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
9073
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...
1
7565
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6805
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
5585
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2938
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.