Page 2 of 4 <1234>
Topic Options
#135425 - 2005-03-15 11:18 PM Re: RFC: ReadXmlString/WriteXmlString
jtokach Offline
Seasoned Scripter
*****

Registered: 2001-11-15
Posts: 513
Loc: PA, USA
I'm playing around with this a bit, but Kix doesn't seem to handle this object model correctly?

Code:
$objXMLDoc = CreateObject("Microsoft.XMLDOM") 
$objXMLDoc.async = False
$=$objXMLDoc.load("C:\my.xml")

$j = " version = " + chr(34) +"1.0" + chr(34)

Dim $objNewPI, $currNode
$objNewPI = $objXMLDoc.createProcessingInstruction("xml", $j)
? "EE0:"@error
? "ES0:"@Serror

$d = $objXMLDoc.firstChild
? "EE1:"@error
? "ES1:"@Serror
$= $objXMLDoc.insertBefore ($objNewPI,$d)
$= $objXMLDoc.save("C:\my.xml")



Beyond that, it seems as though preservewhitespace is completely ignored. With the code you guys have so far, the indenting should be there...
_________________________
-Jim

...the sort of general malaise that only the genius possess and the insane lament.

Top
#135426 - 2005-03-15 11:50 PM Re: RFC: ReadXmlString/WriteXmlString
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
$objXMLDoc.async = False

KiX does not have a keyword named "False"
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#135427 - 2005-03-16 12:05 AM Re: RFC: ReadXmlString/WriteXmlString
jtokach Offline
Seasoned Scripter
*****

Registered: 2001-11-15
Posts: 513
Loc: PA, USA
Umm...
Code:
$objXMLDoc = CreateObject("Microsoft.XMLDOM") 
? "Before "$objXMLDoc.async
$objXMLDoc.async = False
? "After "$objXMLDoc.async

_________________________
-Jim

...the sort of general malaise that only the genius possess and the insane lament.

Top
#135428 - 2005-03-16 12:15 AM Re: RFC: ReadXmlString/WriteXmlString
Jose Offline
Seasoned Scripter
*****

Registered: 2001-04-04
Posts: 693
Loc: Buenos Aires - Argentina
Async

Code:
 
$objNewPI = $objXMLDoc.createProcessingInstruction("xml", $j)


Havent seen function within the XMLDOM object.
_________________________
Life is fine.

Top
#135429 - 2005-03-16 12:30 AM Re: RFC: ReadXmlString/WriteXmlString
jtokach Offline
Seasoned Scripter
*****

Registered: 2001-11-15
Posts: 513
Loc: PA, USA
It adds that header line. Not of any value that I can see for our immediate needs. Got it working, but it's still freakin wierd. I puzzled as to the formatting???

Code:
function LoadXml($filename)
dim $, $rootNode, $objNewPI, $strType

$loadXml = CreateObject("Microsoft.XMLDOM");
$loadXml.async = False
$loadXml.preserverwhitespace = True

if not $loadXml
return
endif

$ = $loadXml.Load($filename)
$strType = " version = " + chr(34) + "1.0" + chr(34)
$objNewPI = $loadXml.createProcessingInstruction("xml", $strType)
$ = $loadXml.insertBefore ($objNewPI,$objXMLDoc.firstChild)

endfunction

_________________________
-Jim

...the sort of general malaise that only the genius possess and the insane lament.

Top
#135430 - 2005-03-16 01:59 AM Re: RFC: ReadXmlString/WriteXmlString
Jose Offline
Seasoned Scripter
*****

Registered: 2001-04-04
Posts: 693
Loc: Buenos Aires - Argentina
I see your point Jim, sorry I didnt undertand.


Quote:


I'm playing around with this a bit, but Kix doesn't seem to handle this object model correctly?




You are right.
The header idea is very good but does not work as it should. Me cannot make it work either.


Code:
  

$objNewPI = $loadXml.createProcessingInstruction("xml", $strType)


I get @error=2147352570

Code:
 

$ = $loadXml.insertBefore ($objNewPI,$objXMLDoc.firstChild)


I get @error=6


I have tryed with the XMLDOM error method ($objXMLDoc.parseError) but nothing. All DOM errors=0.

I think it is compulsory for these udf´s to include this feature and we should find out how. VBScrit source.

Any ideas guys? Can anyone else give a try?
_________________________
Life is fine.

Top
#135431 - 2005-03-16 10:58 AM Re: RFC: ReadXmlString/WriteXmlString
Jose Offline
Seasoned Scripter
*****

Registered: 2001-04-04
Posts: 693
Loc: Buenos Aires - Argentina
Talking to Jooel he suggeted to use the old friend writeline() to write the header.
I am more the opinion of using the same object developed for that purpose but this particular code seems to be stucked using kix.

Thoughts?
_________________________
Life is fine.

Top
#135432 - 2005-03-16 05:54 PM Re: RFC: ReadXmlString/WriteXmlString
jtokach Offline
Seasoned Scripter
*****

Registered: 2001-11-15
Posts: 513
Loc: PA, USA
Jose, that header code works for me, not sure why your seeing those errors.

Regarding writeline(), I'm half tempted to say screw xmldom object model and do everything with arrays, readline and writeline...

Regarding formatting, the single line seems to be the only output xmldom is capable of producing. Formatting is a separate process: Somewhat automated way of formatting .xml

It's in VB, but at a glance, it looks like it can be converted.


Edited by jtokach (2005-03-16 06:01 PM)
_________________________
-Jim

...the sort of general malaise that only the genius possess and the insane lament.

Top
#135433 - 2005-03-16 07:24 PM Re: RFC: ReadXmlString/WriteXmlString
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Jim, not too sure I would dismiss XML so quickly. Personally, I'm hoping to get some screaming performance gains versus the builtin WriteLine and WriteProfileString functions. Although I have no data to back this up, the Kixtart builtins are slow as hell (especially writing stuff). Think some benchmarking is in order.

The other thing ... wish I could figure-out a way to get the output XML properly formatted. When notepadding the result, all the data is scrunched into one long line. Must be a way to introduce some formatting in there.

Top
#135434 - 2005-03-16 07:52 PM Re: RFC: ReadXmlString/WriteXmlString
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
so, you say com stuff is faster than writeline?
uuh...

and who did say anything about dismissing xml?
xml is lot more than the lame com stuff used in this thread.
_________________________
!

download KiXnet

Top
#135435 - 2005-03-16 08:38 PM Re: RFC: ReadXmlString/WriteXmlString
Jose Offline
Seasoned Scripter
*****

Registered: 2001-04-04
Posts: 693
Loc: Buenos Aires - Argentina
Quote:


xml is lot more than the lame com stuff used in this thread.





I dont like this.
_________________________
Life is fine.

Top
#135436 - 2005-03-16 08:45 PM Re: RFC: ReadXmlString/WriteXmlString
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
I knew you wouldn't like it.
you like the com-object.
but finally you have to admit that xml is just pure text and nothing much more.
_________________________
!

download KiXnet

Top
#135437 - 2005-03-16 08:55 PM Re: RFC: ReadXmlString/WriteXmlString
Jose Offline
Seasoned Scripter
*****

Registered: 2001-04-04
Posts: 693
Loc: Buenos Aires - Argentina
Com or text is the same as you said, and there sure are thrid party ways of doing it too.

What I dont like is you making that opinion about something I had involved in.
_________________________
Life is fine.

Top
#135438 - 2005-03-16 10:37 PM Re: RFC: ReadXmlString/WriteXmlString
jtokach Offline
Seasoned Scripter
*****

Registered: 2001-11-15
Posts: 513
Loc: PA, USA
Quote:

Jim, not too sure I would dismiss XML so quickly. Personally, I'm hoping to get some screaming performance gains versus the builtin WriteLine and WriteProfileString functions. Although I have no data to back this up, the Kixtart builtins are slow as hell (especially writing stuff). Think some benchmarking is in order.




If it wasn't so complicated, I wouldn't mind so much, but it sucks and something seems to be unpredictable. Again, I renew my request for builtin xml support in Kix. =)

Quote:

The other thing ... wish I could figure-out a way to get the output XML properly formatted. When notepadding the result, all the data is scrunched into one long line. Must be a way to introduce some formatting in there.



I posted this in the previous post. It's written in VB. It is terribly inconvenient but not sure it's that big of an issue. We'll need to stick to IE until someone can translate that VB code. I started, but I can't find a suitable replacement for the TypeOf statements, yet...
_________________________
-Jim

...the sort of general malaise that only the genius possess and the insane lament.

Top
#135439 - 2005-03-17 06:09 PM Re: RFC: ReadXmlString/WriteXmlString
jtokach Offline
Seasoned Scripter
*****

Registered: 2001-11-15
Posts: 513
Loc: PA, USA
Hail to the King Baby!

-Formatting hooked up! (Needed to apply XSL)
-Updated all code for Option Explicit

Code:
break on

$nul=SetOption("ASCII","On")
$nul=SetOption("Explicit","On")

Dim $filename,$xml,$

$filename = "C:\HailToTheKingBaby.xml"

$xml = LoadXml($filename)

$= WriteXmlValue($xml, "korg/shawn/number", 119)
$= WriteXmlValue($xml, "korg/jose/number", 1772)
$= WriteXmlValue($xml, "korg/jooel/number", 2087)

?"Value=" ReadXmlValue($xml, "korg/jose/number")

SaveXml($xml, $filename)
$xml = 0
exit 1

function LoadXml($filename)
dim $, $rootNode, $objNewPI, $strType

$loadXml = CreateObject("Microsoft.XMLDOM")
$loadXml.async = False
$loadXml.preserverwhitespace = True

if not $loadXml
return
endif

$ = $loadXml.Load($filename)
endfunction


Function FormatXML($objXMLDOM)
Dim $,$strXSL,$objXSL
;Create and Load XSL
; <?xml version="1.0" encoding="UTF-8"?>
; <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
; <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
; <xsl:template match="/ | @* | node()">
; <xsl:copy>
; <xsl:apply-templates select="@* | node()" />
; </xsl:copy>
; </xsl:template>
; </xsl:stylesheet>

$strXSL = "<?xml version=" + chr(34) + "1.0" + chr(34) + " encoding=" +
chr(34) + "UTF-8" + chr(34) + "?>" + @CRLF
$strXSL = $strXSL + "<xsl:stylesheet version=" + chr(34) + "1.0" + chr(34) +
" xmlns:xsl=" + chr(34) + "http://www.w3.org/1999/XSL/Transform" +
chr(34) + ">" + @CRLF
$strXSL = $strXSL + "<xsl:output method=" + chr(34) + "xml" + chr(34) +
" version=" + chr(34) + "1.0" + chr(34) + " encoding=" + chr(34) +
"UTF-8" + chr(34) + " indent=" + chr(34) + "yes" + chr(34) + "/>" + @CRLF
$strXSL = $strXSL + "<xsl:template match=" + chr(34) + "/ | @@* | node()" +
chr(34) + ">" + @CRLF
$strXSL = $strXSL + "<xsl:copy>"+ @CRLF
$strXSL = $strXSL + "<xsl:apply-templates select=" + chr(34) +
"@@* | node()" + chr(34) + " />"+ @CRLF
$strXSL = $strXSL + "</xsl:copy>"+ @CRLF
$strXSL = $strXSL + "</xsl:template>"+ @CRLF
$strXSL = $strXSL + "</xsl:stylesheet>"

;? "XLM Stylesheet: " + @CRLF + $strXSL

$objXSL = CreateObject("Microsoft.XMLDOM")
$objXSL.async = false
$=$objXSL.loadXML($strXSL)

;Transform file
$objXMLDOM.TransformNodeToObject ($objXSL, $objXMLDOM)
$formatXML = $objXMLDOM
EndFunction


function WriteXmlValue($xml, $path, $value)
dim $p, $rootNode, $sectionNode, $parentNode, $childNode,$node
$sectionNode = $xml.SelectSingleNode($path);

if not $sectionNode
$parentNode = $xml

for each $node in split($path,"/")
$p = $p + $node
$sectionNode = $xml.SelectSingleNode($p)

if not $sectionNode
$sectionNode = $xml.CreateElement($node)
$parentNode = $parentNode.AppendChild($sectionNode)
else
$parentNode = $sectionNode
endif

$p = $p + "/"
next
endif

if $sectionNode
$sectionNode.Text = $value
endif
endfunction

function SaveXml($xml, $filename)
$xml = formatXML($xml)
$SaveXml = $xml.Save($filename)
endfunction


function ReadXmlValue($xml, $key, optional $defaultValue)
dim $sectionNode

$sectionNode = $xml.SelectSingleNode($key);

if not $sectionNode
$ReadXmlValue = $defaultValue;
else
$ReadXmlValue = $sectionNode.FirstChild.Text;
endif
endfunction



Edited by jtokach (2005-03-18 08:06 PM)
_________________________
-Jim

...the sort of general malaise that only the genius possess and the insane lament.

Top
#135440 - 2005-03-17 06:57 PM Re: RFC: ReadXmlString/WriteXmlString
jtokach Offline
Seasoned Scripter
*****

Registered: 2001-11-15
Posts: 513
Loc: PA, USA
Jose, I updated your attrib UDF's. Also renamed the one from Rear to Read (I assumed that was a typo.)

Code:
Function WriteXMLattrib($xml, $Path, $Attr, $Value)

Dim $SelectionTag,$AttrTag,$,$eu
$SelectionTag = $xml.getElementsByTagName($Path)
$AttrTag = $SelectionTag.item(0)
If @Serror = "Member not found."
$= WriteXmlValue($xml, $path, "")
$SelectionTag = $xml.getElementsByTagName($Path)
$AttrTag = $SelectionTag.item(0)
EndIf
$eu = $AttrTag.SetAttribute($Attr,$Value)
EndFunction


Function ReadXMLattrib($xml, $Path, $Attr)
Dim $SelectionTag,$AttrName
$SelectionTag = $xml.getElementsByTagName($Path)
$AttrName = $SelectionTag.item(0)
If @Serror = "Member not found."
$ReadXMLattrib = ""
Exit @Error
Else
$ReadXMLattrib =$AttrName.getAttribute($Attr)
EndIf
EndFunction



Edited by jtokach (2005-03-17 06:59 PM)
_________________________
-Jim

...the sort of general malaise that only the genius possess and the insane lament.

Top
#135441 - 2005-03-17 07:07 PM Re: RFC: ReadXmlString/WriteXmlString
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11624
Loc: CA
FYI - Link to XSL that Jim refers to.

http://www.w3.org/Style/XSL/

Learning link
http://www.w3schools.com/xsl/

XSL Frequently Asked Questions
http://www.dpawson.co.uk/xsl/xslfaq.html

Top
#135442 - 2005-03-17 08:20 PM Re: RFC: ReadXmlString/WriteXmlString
Jose Offline
Seasoned Scripter
*****

Registered: 2001-04-04
Posts: 693
Loc: Buenos Aires - Argentina


Jim you have done a fantastic job man!!

LOL Rear. Havent realized . Silly me
ReadXMLattrib() looks much better.
_________________________
Life is fine.

Top
#135443 - 2005-03-17 09:22 PM Re: RFC: ReadXmlString/WriteXmlString
Jose Offline
Seasoned Scripter
*****

Registered: 2001-04-04
Posts: 693
Loc: Buenos Aires - Argentina
Jim:
I have changed two things in the attrib functions.
- I have spanish languaje so changed to @error in case path not exist.
- took the $eu off and replaced with $Write

Code:
  
Function WriteXMLattrib($xml, $Path, $Attr, $Value)

Dim $SelectionTag,$AttrTag,$,$Write

$SelectionTag = $xml.getElementsByTagName($Path)

$AttrTag = $SelectionTag.item(0)

If @ERROR = "-2147352573"

$= WriteXmlValue($xml, $path, "")

$SelectionTag = $xml.getElementsByTagName($Path)

$AttrTag = $SelectionTag.item(0)

EndIf

$write = $AttrTag.SetAttribute($Attr,$Value)

EndFunction


Function ReadXMLattrib($xml, $Path, $Attr)

Dim $SelectionTag,$AttrName

$SelectionTag = $xml.getElementsByTagName($Path)

$AttrName = $SelectionTag.item(0)

If @ERROR = "-2147352573"

$ReadXMLattrib = ""

Exit @Error

Else

$ReadXMLattrib =$AttrName.getAttribute($Attr)

EndIf

EndFunction

_________________________
Life is fine.

Top
#135444 - 2005-03-17 10:35 PM Re: RFC: ReadXmlString/WriteXmlString
jtokach Offline
Seasoned Scripter
*****

Registered: 2001-11-15
Posts: 513
Loc: PA, USA
Jose,

Sorry for being so ignorant!!! It didn't even occur to me that @serror would be different b/w languages.

I think we need some more though as to how this is going to progress. I'm thinking we need and EnumXML().

Also, not sure that LoadXML and SaveXML are the best method of approaching this. Shouldn't these be built right into all of the Write and Read functions; like ReadProfileString and WriteProfileString? Granted that there would be much more overhead, but much simpler to write code with. I guess that's where you'd lose your performance gain, eh Shawn? But, at least I'd be able to perform a Read operation right after write operation because the data is immediately commited to disk.

Current:
Code:

LoadXML()
Get data...
WriteXMLValue()
Get more data...
WriteXMLValue()
SaveXML()

and

LoadXML()
ReadXMLValue()
ReadXMLValue()
SaveXML()



Jim Preferred:
Code:

WriteXMLValue()
ReadXMLValue()
WriteXMLValue()
ReadXMLValue()
ReadXMLValue()
WriteXMLValue()

_________________________
-Jim

...the sort of general malaise that only the genius possess and the insane lament.

Top
Page 2 of 4 <1234>


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 566 anonymous users online.
Newest Members
Timothy, Jojo67, MaikSimon, kvn317, kixtarts2025
17874 Registered Users

Generated in 0.075 seconds in which 0.025 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org