New topic: 

Problem Parsing XML file authored on Windows (with CRLF)

<http://forums.realsoftware.com/viewtopic.php?t=29391>

       Page 1 of 1
   [ 1 post ]                 Previous topic | Next topic         Author  
Message       Carl Adler           Post subject: Problem Parsing XML file 
authored on Windows (with CRLF)Posted: Tue Aug 04, 2009 2:59 pm                 
       
Joined: Thu Apr 05, 2007 11:35 am
Posts: 71              While working with XML files I noticed that text 
contained in a node that carried line endings CRLF would come through with just 
the LF and no CR. This happened even if you used ReplaceLineEndings on the XML 
file first.

To test this I used an example from "xmlforn00bs" that reads the titles of 
books in an XML file in a EditField.
Using WordPad I changed the title "Grapes of Wrath" to
one two three
for five six
and directed the results to a second EditField.
The result showed in EditField2 as
one two three
four five six
But when I copied this and pasted it into BBEdit it showed

one two three four five six
with a LF character between the three and four but no CR.

this happened even if I used
  EditField1.text=ReplaceLineEndings(EditField1.text,endofline.Macintosh)
or
  EditField1.text=ReplaceLineEndings(EditField1.text,endofline)
before using the XML file!

I assumed that by default the text in the node was not parsed.
(The difference between CDATA and PCDATA? I really don't know)
But if is not parsed why is the CR removed?

Next I replaced
 EditField2.text=EditField2.text+endofline+title.Child( 0 ).Value
with
  Endtest=ReplaceLineEndings(title.Child(0).value,EndofLine)
  EditField2.text=EditField2.text+endofline+EndTest

and got the correct result, that is the LF was removed leaving just the CR

Thus both in the EditField and pasted into BBEdit the result was
one two three
four five six

Any help, suggestions, enlightenment greatly appreciated. I am really a n00by 
at this.

Carl (Actual code follows)

//-----

  dim endtest as string
  'EditField1.text=ReplaceLineEndings(EditField1.text,endofline.Macintosh)
  'EditField1.text=ReplaceLineEndings(EditField1.text,endofline)
  dim doc as new XmlDocument( EditField1.Text )
  dim bookshelf as XmlNode = doc.Child( 0 )
  dim books as XmlNodeList = bookshelf.Xql( "book/title" )
  for i as integer = 0 to books.Length - 1
  dim title as XmlNode = books.Item( i )
  Endtest=ReplaceLineEndings(title.Child(0).value,EndofLine)
  'EditField2.text=EditField2.text+endofline+title.Child( 0 ).Value
  EditField2.text=EditField2.text+endofline+EndTest
  next
//---end code   
                            Top           Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 1 post ]     
-- 
Over 1500 classes with 29000 functions in one REALbasic plug-in collection. 
The Monkeybread Software Realbasic Plugin v9.3. 
http://www.monkeybreadsoftware.de/realbasic/plugins.shtml

[email protected]

Reply via email to