SetXMLAttribute with #LFCR$

Just starting out? Need help? Post your questions and find answers here.
User avatar
lazarusoft
User
User
Posts: 23
Joined: Wed Jan 10, 2007 10:17 pm
Location: Brasil

SetXMLAttribute with #LFCR$

Post by lazarusoft »

Code: Select all

;
; BUG Purebasic 5.30 Beta 7 x 1 Brazil
;
OpenWindow(0, 0, 0, 322, 150, "EditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
EditorGadget(1, 8, 8, 306, 133)
For a = 0 To 5
  AddGadgetItem(1, a, "Line "+Str(a))
Next
;  
WaitWindowEvent()

Define.s tx = GetGadgetText(1)

Delay(100)

Define xml = CreateXML(#PB_Any,#PB_UTF8) 
;SetXMLEncoding(xml,#PB_UTF8)
Define mainNode = CreateXMLNode(RootXMLNode(xml),"Zoo") 
Define item = CreateXMLNode(mainNode,"Animal") 
SetXMLAttribute(item, "id", tx);Bug
;SetXMLNodeText(item, tx);OK
FormatXML(xml,#PB_XML_CutNewline)
Define xmlsize = ExportXMLSize(xml)
Define *Memx=AllocateMemory(xmlsize) 
ExportXML(xml, *Memx, xmlsize);
;Debug GetXMLEncoding(xml)
Define nxml$=PeekS(*Memx, xmlsize) ; in 5.22 OK
Debug nxml$  

Debug ComposeXML(xml);Change utf8 to ascii

End
JAVA é como uma Ferrari, mas a diferença é que a Ferrari está em um caminhão cegonha... JAVA is like a Ferrari, but the difference is that Ferrari is in a truck stork ...
User avatar
STARGÅTE
Addict
Addict
Posts: 2227
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: SetXMLAttribute with #LFCR$

Post by STARGÅTE »

Can you explain the bug? I don't understand the code and the output.
㼼浸敶獲潩㵮ㄢ〮•湥潣楤杮∽呕ⵆ∸㸿娼潯㰾湁浩污椠㵤䰢湩⁥☰ㄣ㬳⌦〱䰻湩⁥☱ㄣ㬳⌦〱䰻湩⁥☲ㄣ㬳⌦〱䰻湩⁥3
<?xml version="1.0" encoding="UTF-16"?><Zoo><Animal id="Line 0&#13;&#10;Line 1&#13;&#10;Line 2&#13;&#10;Line 3&#13;&#10;Line 4&#13;&#10;Line 5&#13;&#10;"/></Zoo>
ExportXMLSize() gives the size in bytes but PeekS() needs a length in characters!
FormatXML() don't formats attributes: "The formatting of the parsed XML document is stored in the 'text' and 'offset' fields of each node"
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
User avatar
lazarusoft
User
User
Posts: 23
Joined: Wed Jan 10, 2007 10:17 pm
Location: Brasil

Re: SetXMLAttribute with #LFCR$

Post by lazarusoft »

Code: Select all

OpenWindow(0, 0, 0, 322, 150, "EditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
EditorGadget(1, 8, 8, 306, 133)
For a = 0 To 5
  AddGadgetItem(1, a, "Line "+Str(a))
Next
;  
WaitWindowEvent() 
;
Define.s tx = GetGadgetText(1)
;
Define xml = CreateXML(#PB_Any,#PB_UTF8) 
CompilerIf #PB_Compiler_Version =530
  Define mainNode = CreateXMLNode(RootXMLNode(xml),"Zoo") 
  Define item = CreateXMLNode(mainNode,"Animal") 
CompilerElse
  Define mainNode = CreateXMLNode(RootXMLNode(xml)) 
  SetXMLNodeName(mainNode, "Zoo")
  Define item = CreateXMLNode(mainNode) 
  SetXMLNodeName(mainNode, "Animal")
CompilerEndIf  
SetXMLAttribute(item, "id", tx) 
;SetXMLNodeText(item, tx)  
FormatXML(xml,#PB_XML_CutNewline)
Define xmlsize = ExportXMLSize(xml)
Define *Memx=AllocateMemory(xmlsize) 
ExportXML(xml, *Memx, xmlsize);
                           
Define nxml$=PeekS(*Memx, xmlsize);

Debug nxml$  

End
Debug In Purebasic 5.22
<?xml version="1.0" encoding="UTF-8"?><Animal>< id="Line 0
Line 1
Line 2
Line 3
Line 4
Line 5
"/></Animal>

Debug in Purebasic 5.30b7
<?xml version="1.0" encoding="UTF-8"?><Animal>< id="Line 0&#13;&#10;Line 1&#13;&#10;Line 2&#13;&#10;Line 3&#13;


The xml version 5.30b7 of the error with a memory transfer
JAVA é como uma Ferrari, mas a diferença é que a Ferrari está em um caminhão cegonha... JAVA is like a Ferrari, but the difference is that Ferrari is in a truck stork ...
User avatar
Comtois
Addict
Addict
Posts: 1431
Joined: Tue Aug 19, 2003 11:36 am
Location: Doubs - France

Re: SetXMLAttribute with #LFCR$

Post by Comtois »

; BUG Purebasic 5.30 Beta 7 x 1 Brazil
:mrgreen:
Please correct my english
http://purebasic.developpez.com/
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Re: SetXMLAttribute with #LFCR$

Post by freak »

This is not a bug. Newline characters are not allowed in XML attributes, so they are encoded with the appropriate character entities.
quidquid Latine dictum sit altum videtur
User avatar
lazarusoft
User
User
Posts: 23
Joined: Wed Jan 10, 2007 10:17 pm
Location: Brasil

Re: SetXMLAttribute with #LFCR$

Post by lazarusoft »

I'll switch to SetXMLNodeText,
but in PureBasic 5.22 is working well,
for this reason I thought it was a bug.

; Purebasic 5.30 Beta 7 x 1 Brazil :oops:
JAVA é como uma Ferrari, mas a diferença é que a Ferrari está em um caminhão cegonha... JAVA is like a Ferrari, but the difference is that Ferrari is in a truck stork ...
Post Reply