473,748 Members | 2,227 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Would a lack of line breaks in a doc cause parsing problems ?

I am fetching some product feeds with PHP like this

$merch = substr($key,1);
$feed = file_get_conten ts($_POST['data_url'.$mer ch]);
$fp = fopen("./feeds/feed".$merch.". txt","w+");
fwrite ($fp,$feed);
fclose ($fp);

and then parsing them with PHP's native parsing functions. This is
succesful for most of the feeds, but a couple of them claim to be
empty when I know they are not. On inspection, the thing these failing
feeds have in common is that they contain no line breaks at all.
Should this cause a problem ?

Sep 26 '07 #1
13 2833
HI Charlie

"charliefortune " <go****@charlie fortune.comskre v i en meddelelse
news:11******** **************@ 50g2000hsm.goog legroups.com...
>I am fetching some product feeds with PHP like this

$merch = substr($key,1);
$feed = file_get_conten ts($_POST['data_url'.$mer ch]);
$fp = fopen("./feeds/feed".$merch.". txt","w+");
fwrite ($fp,$feed);
fclose ($fp);

and then parsing them with PHP's native parsing functions. This is
succesful for most of the feeds, but a couple of them claim to be
empty when I know they are not. On inspection, the thing these failing
feeds have in common is that they contain no line breaks at all.
Should this cause a problem ?
Just to be sure, You are talking about Xml files ?

Whitespaces in a xml file are discarded, so it shouldn't matter, but
hey I'm just a newbee, so maybe someone else knows more.

But You should post a little sample of the xml file that cources the
error. that would make it easier to give adwise.

Kind regards
Asger
Sep 26 '07 #2
charliefortune wrote:
I am fetching some product feeds with PHP like this

$merch = substr($key,1);
$feed = file_get_conten ts($_POST['data_url'.$mer ch]);
$fp = fopen("./feeds/feed".$merch.". txt","w+");
fwrite ($fp,$feed);
fclose ($fp);

and then parsing them with PHP's native parsing functions. This is
succesful for most of the feeds, but a couple of them claim to be
empty when I know they are not. On inspection, the thing these failing
feeds have in common is that they contain no line breaks at all.
Should this cause a problem ?
The code you show above is not XML or feed specific, you are simply
using PHP file IO to fetch contents and write it to a file.
If you have trouble parsing such a file later with "PHP's native
parsing" functions then show us that code and show us a sample of a feed
where it does not work as you want it to work.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Sep 26 '07 #3
Not for any compliant XML parser. Excess line breaks in the wrong places
might.

Since I don't use PHP, I can't speak to whether it has any limitations.
Contact its authors or support group?

--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
Sep 26 '07 #4
Hi Richard

"Richard Tobin" <ri*****@cogsci .ed.ac.ukskrev i en meddelelse
news:fd******** ***@pc-news.cogsci.ed. ac.uk...
In article <p1************ *@news.get2net. dk>,
Asger Jørgensen <Ju**@Asger-P.dkwrote:
>>Whitespaces in a xml file are discarded

This is not true. Whitespace in markup (e.g. between attributes) is
unimportant, but XML parsers must return all whitespace in text
content, even the possibly-unimportant whitespace between elements in
element-only content.
You are absolutely right, whitespace can be importent, but since the
question
was about line breaks, I wasn't that much off..;-)

Thanks for pointing it out.

Kind regards
Asger
Sep 26 '07 #5
Hi Charlie

"charliefortune " <go****@charlie fortune.comskre v i en meddelelse
news:11******** **************@ r29g2000hsg.goo glegroups.com.. .
On 26 Sep, 13:23, rich...@cogsci. ed.ac.uk (Richard Tobin) wrote:
In article <p1qKi.41$cQ4.. .@news.get2net. dk>,
Here is one of the ones that doesn't work
http://fcshirtshop.com/feeds/feed1058.txt.
I can't find anything wrong wrong with the file either.
but I cant find any indications that the encoding should be UTF-8 either
unless thats the accepted default (XML Newbee You know)
At least the file don't say anything and there is no BOM.
The file must be a dificult on though, IE was working for 15 minutes
on the file and it was only half way throught when I closed it
it didn't report any errors though.

One trick You could try though.

You could do a searc and replace on the file before You parse it:

Look for: "<!" and replace it with "\n<!"
\n being new line

There is a <![CDATA in allmost every element
so that would give You enough linebreaks for Your
parser to cope with it. If it is the missing
linebreaks that gives the trouble.

Kind regards
Asger
Sep 26 '07 #6
In article <us************ *@news.get2net. dk>,
Asger Jørgensen <Ju**@Asger-P.dkwrote:
>I can't find anything wrong wrong with the file either.
but I cant find any indications that the encoding should be UTF-8
It only contains ascii characters, so as long as you don't use ebcdic...

-- Richard
--
"Considerat ion shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
Sep 26 '07 #7
Asger Jørgensen wrote:
but I cant find any indications that the encoding should be UTF-8 either
unless thats the accepted default (XML Newbee You know)
Most XML parsers will autodetect UTF-16, and will fall back to UTF8. The
XML spec describes how to do that.
There is a <![CDATA in allmost every element
Haven't looked, but I'd bet failure to balance those properly is what's
causing the problems. CDATA Sections are almost always bad practice, for
that reason among many others.

--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
Sep 27 '07 #8
Hi Joe

"Joe Kesselman" <ke************ @comcast.netskr ev i en meddelelse
news:SP******** *************** *******@comcast .com...
>
Most XML parsers will autodetect UTF-16, and will fall back to UTF8. The
XML spec describes how to do that.
Yea, I've seen that done in some source code, that is not the easiest thing
to do, but from a look in the PHP manual it sais nothing about selfdetecting
encoding and it states that PHP defaults to ISO-8859-1.
but I gues nothing will happen if You try to decode
a US ASCII as UTF-8, except for the waste of time.
>There is a <![CDATA in allmost every element

Haven't looked, but I'd bet failure to balance those properly is what's
causing the problems. CDATA Sections are almost always bad practice, for
that reason among many others.
Well, those CDATA sections are quite simple, in this file they are simply
used
whenever the element contain text.
Which by the way got me thinking about my own hobby parser, I just throw
those CDATA sections away, I gues thats not the best way <g>

Kind regards
Asger
Sep 27 '07 #9
In article <11************ *********@d55g2 000hsg.googlegr oups.com>,
Andy Dingley <di*****@codesm iths.comwrote:
>There's also a lot of CDATA sections in there, in contexts where it's
far from necessary to use them. Could they be what's confusing the
parser?
Matching up brackets in huge strings is supposed to be just the sort
of thing computers are good at! I think a line-length limit is the
most likely explanation.

-- Richard

--
"Considerat ion shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
Sep 27 '07 #10

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

Similar topics

9
17976
by: leegold | last post by:
Why does float:right cause a line break? Try the code below. Is there a fix? I want the link on the same line as the text. Thanks <html> <head> <STYLE> span.linkpos { float:right; clear: none; color:blue; } </style> </head>
1
346
by: ChrisC | last post by:
Im having trouble removing line breaks from my c# string. Actually, im having trouble getting .Trim() to work properly, as it seems to count a string that has nowt but a break of some sort as not being empty. To get trim to work properly im trying to axe out the line breaks seperately. Ive got .replace("/r") and "/n" but still having problems with some strings. Are there paragraph markers or something I should be removing too? how do i...
7
1169
by: S Borg | last post by:
Hello, I am parsing text from one document to another. I have a scheme similar to: for x in myfoobar: print >> mytextfile, "%s " % mydictionary, #all on same line print >> mytextfile, '\n' #new line
4
58507
by: Water Cooler v2 | last post by:
Besides embedding <BR/>, like general purpose programming languages, I thought you could embed escape sequences such as \n or \r\n into string arguments to cause line breaks in JavaScript. To test, I tried this: <BODY> <BR/><BR/>
5
16852
by: joelbyrd | last post by:
Didn't know exactly where to post this, but: How do I get line breaks in a textarea? I'm pulling text from a database, and this text definately has line breaks in it, because I replaced all the line breaks with <br /> tags ( using the php function nl2br() ), and <br /> tags showed up in the textarea.
1
2155
by: Sky | last post by:
Yesterday I was told that GetType(string) should not just be with a Type, but be Type, AssemblyName. Fair enough, get the reason. (Finally!). As long as it doesn't cause tech support problems down the line... What happens when my code is run on a station that only has framework 3.0 or 4.0, and this assembly, with version number defined for 2.0.0.0 , isn't available. ...breaks? Second question: Does an assembly's PublicKeyToken change...
1
1945
by: =?ISO-8859-1?Q?thib=B4?= | last post by:
Hi, Taking a closer look to highlight_file() lastly, I found out that its line break policy was a bit.. strange. <?php # highlight_file() line breaks test $f = fopen('highlight_file_test', 'w'); fwrite($f, highlight_file(__FILE__, true)); fclose($f); ?>
2
1489
by: Bill H | last post by:
I have the same version of php running on our linux server as I have on my local xampp runing under windows. While working yesterday a piece of code I wrote just wouldn't work on the server, but ran fine under xampp. The code in question opened a file and reads in the contents line by line using a construct similar to this: if ($line != "") { $xmlString .= "<setup value\"$line\" />\n"; }
53
12130
by: Gianni Mariani | last post by:
Do you have a preference on maximum line width for C++ code? I've seen the craziest debates on this most silly of topic. I have witnessed engineers spent oodles of time fiddling with line breaks just to get it right. I find in general a prescriptive rule makes for markedly less readable code, which unfortunately is a subjective argument, however, the waste of time modifying code when it does not need to is not.
0
8831
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
9552
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9326
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
8245
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
6076
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
4607
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...
0
4877
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2787
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2215
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.