I am trying to use repeat to display the "Species" node of each of the "XmlNode"s. However, I keep getting an error. I am a new to LiveCode and have tried everything I can think of.
XML CODE:
<ArrayOfXmlNode xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.petango.com/">
<XmlNode>
<adoptableSearch xmlns="">
<ID>12063964</ID>
<Name>152217</Name>
<Species>Dog</Species>
<Sex>Male</Sex>
<PrimaryBreed>Doberman Pinscher</PrimaryBreed>
<SecondaryBreed>Mix</SecondaryBreed>
<SN>Neutered</SN>
<Age>70</Age>
<Photo>
http://www.petango.com/sms/photos/119/6cd81b69-357c-4272-b064- d3fb3038985e_TN1.jpg
</Photo>
<Location>Adoption</Location>
<OnHold>No</OnHold>
<SpecialNeeds></SpecialNeeds>
<NoDogs></NoDogs>
<NoCats></NoCats>
<NoKids></NoKids>
<BehaviorResult></BehaviorResult>
<MemoList/>
<ARN></ARN>
<BehaviorTestList></BehaviorTestList>
<Stage>Available</Stage>
<AnimalType>Dog</AnimalType>
<AgeGroup>Adult</AgeGroup>
<WildlifeIntakeInjury></WildlifeIntakeInjury>
<WildlifeIntakeCause></WildlifeIntakeCause>
<BuddyID>0</BuddyID>
<Featured>No</Featured>
<Sublocation>K27</Sublocation>
<ChipNumber>0A12047D2B</ChipNumber>
</adoptableSearch>
</XmlNode>
<XmlNode>
<adoptableSearch xmlns="">
<ID>13423810</ID>
<Name>145957</Name>
<Species>Dog</Species>
<Sex>Male</Sex>
<PrimaryBreed>Chihuahua, Short Coat</PrimaryBreed>
<SecondaryBreed>Mix</SecondaryBreed>
<SN>Neutered</SN>
<Age>99</Age>
<Photo>
http://www.petango.com/sms/photos/119/5839bd2b-f15e-4e40-b5e1-9a20331de212_TN1.jpg
</Photo>
<Location>Stray Room</Location>
<OnHold>No</OnHold>
<SpecialNeeds></SpecialNeeds>
<NoDogs></NoDogs>
<NoCats></NoCats>
<NoKids></NoKids>
<BehaviorResult></BehaviorResult>
<MemoList/>
<ARN></ARN>
<BehaviorTestList></BehaviorTestList>
<Stage>72 hour hold</Stage>
<AnimalType>Dog</AnimalType>
<AgeGroup>Baby</AgeGroup>
<WildlifeIntakeInjury></WildlifeIntakeInjury>
<WildlifeIntakeCause></WildlifeIntakeCause>
<BuddyID>0</BuddyID>
<Featured>No</Featured>
<Sublocation>Stray Room 8</Sublocation>
<ChipNumber>0A123F1156</ChipNumber>
</adoptableSearch>
</XmlNode>
LIVECODE CODE:
on mouseUp
put url "http://www.petango.com/webservices/wsadoption.asmx/AdoptableSearch?authkey=XXXXXX&speciesID=&sex=&ageGroup=&location=&site=&onHold=&orderBy=&primaryBreed=&secondaryBreed=&specialNeeds=&noDogs=&noCats=&noKids=&stageID=" into tURL
put revCreateXMLTree( tURL, true, true, false) into tInfo
put revXMLChildNames( tInfo, "ArrayOfXmlNode", return, , true) into tChildren
repeat for each line tChild in tChildren
put revXMLNodeContents( tInfo, "ArrayOfXmlNode/" & tChild & "/Species") &
return after tSpecies
end repeat
put tSpecies
end mouseUp
Could you please try the following which includes adoptableSearch in the node path:
on mouseUp
put url "http://www.petango.com/webservices/wsadoption.asmx/AdoptableSearch?authkey=XXXXXX&speciesID=&sex=&ageGroup=&location=&site=&onHold=&orderBy=&primaryBreed=&secondaryBreed=&specialNeeds=&noDogs=&noCats=&noKids=&stageID=" into tURL
put revCreateXMLTree( tURL, true, true, false) into tInfo
put revXMLChildNames( tInfo, "ArrayOfXmlNode", return, , true) into tChildren
repeat for each line tChild in tChildren
put revXMLNodeContents( tInfo, "ArrayOfXmlNode/" & tChild & "/adoptableSearch/Species") &
return after tSpecies
end repeat
put tSpecies
end mouseUp
Related
I'm using Xmlwriter method to write an html document. When adding elements, it automatically inserts crlf linebreaks between them, no problem there.
Except at some point, when I want to add some tags in my inner text: what I get is a crlf after each , which is definitely not desirable.
I can live without linebreaks between elements, but I can't find the setting in the xmlwriter that could give me this... As far as I can tell, .NewLineHandling only deals with linebreaks in text, not those inserted automatically between elements.
Here are my settings:
With ReportSet 'XML/HTML file writing settings
.Encoding = Text.Encoding.UTF8
.Indent = True
.IndentChars = vbTab
.OmitXmlDeclaration = True
.NewLineHandling = Xml.NewLineHandling.None
End With
And here is the spot where I definitely don't want any linebreak between elements:
For Each section As DiffLib.DiffSection In test
If section.IsMatch Then
cp = EltCnt(k).Substring(n, section.LengthInCollection1)
Report.WriteString(cp)
Else
rmv = EltCnt(k).Substring(n, section.LengthInCollection1)
add = EltCntR(k).Substring(o, section.LengthInCollection2)
With Report
.WriteStartElement("SPAN")
.WriteAttributeString("style", "background-color: #ffcccc; text-decoration: line-through;")
.WriteString(rmv)
.WriteEndElement()
.WriteStartElement("SPAN")
.WriteAttributeString("style", "background-color: #ccffcc;")
.WriteString(add)
.WriteEndElement()
End With
End If
n += section.LengthInCollection1
o += section.LengthInCollection2
Next
So: what should I do not to have linebreaks between the tags?
Never mind, browsers are smarter than me, and just ignore those pesky linebreaks... No need to remove them.
Followed the below steps to save a file in desired location:
Step1: Save As window getting opened(with the default downloads location, with file name as DOC)
Step2: entering the file name as "D:\temp\sample.pdf" (which is getting entered in the edit bar)
Step3: clicking the save button (button clicked, file downloaded in the default location rather than the "D:\temp" location)
I have created an .exe with the below .au3 script
WinWait("[CLASS:#32770]","",10)
Sleep(2000)
ControlSetText("Save As", "", "Edit1", $CmdLine[1])
Sleep(5000)
ControlClick("Save As", "", "Button1");
Sleep(5000)
On clicking save, it is getting saved in the default location rather than the specified location.
The below code, executing the script.
IO.popen('autoit_script.exe D:\temp') #Ruby Code
Is there a way to sort it out?
It depends on the software you are trying to automate but usually this happens because the software is not recognizing there is a change in the file save path box. The problem is in how ControlSetText works. Try using ControlSend with some error checking to make sure the file path you are try to set is getting put in right. Sometimes you have to play with a few different variations to see what works with the software you are automating. Here are two examples you can try:
Example one:
WinWait("[CLASS:#32770]", "", 10)
If Not #error Then ;make sure the window was found
$hWin = WinGetHandle("[CLASS:#32770]") ;get window handle
ControlSetText($hWin, "", "Edit1", $CmdLine[1]) ;set text
ControlFocus($hWin, "", "Edit1") ;just to make sure we have focus
ControlSend($hWin, "", "Edit1", "{ENTER}")) ;should work like click button 1 but you will have to check
;better then a sleep
$hTimer = TimerInit() ; Begin the timer and store the handle in a variable.
Do
Until WinExists($hWin) = 0 Or TimerDiff($hTimer) >= 10000
EndIf
Example two:
WinWait("[CLASS:#32770]", "", 10)
If Not #error Then ;make sure the window was found
$hWin = WinGetHandle("[CLASS:#32770]") ;get window handle
While 1
ControlSetText($hWin, "", "Edit1", "") ;just makes sure there is no text in the control text
ControlFocus($hWin, "", "Edit1") ;just to make sure we have focus
ControlSend($hWin, "", "Edit1", $CmdLine[1])) ;set text using ControlSend
If ControlGetText($hWin, "", "Edit1") = $CmdLine[1] Then ExitLoop ;makes sure that the control got ALL of the text before exiting loop
WEnd
ControlClick($hWin, "", "Button1");
;better then a sleep
$hTimer = TimerInit() ; Begin the timer and store the handle in a variable.
Do
Until WinExists($hWin) = 0 Or TimerDiff($hTimer) >= 10000
EndIf
Read at the source code https://github.com/jspahrsummers/libextobjc/blob/master/extobjc/metamacros.h#L158
// expands to true
metamacro_if_eq(0, 0)(true)(false)
when is expand the macro metamacro_if_eq(0, 0) manually, i get the following
metamacro_if_eq0(0) (true) (false)
continue expanding.
metamacro_if_eq0_0() (true) (false)
go on.
metamacro_consume_ (true) (false)
metamacro_consume is defined as:
#define metamacro_consume_(...) // why nothing here ?
then how can I get the expected value of "true" ?
Your production is incorrect. The operations go like this:
metamacro_if_eq(0, 0)(true)(false)
metamacro_concat(metamacro_if_eq, 0)(0)(true)(false)
metamacro_concat_(metamacro_if_eq, 0)(0)(true)(false)
metamacro_if_eq0(0)(true)(false)
metamacro_concat(metamacro_if_eq0_, 0)(true)(false)
metamacro_concat_(metamacro_if_eq0_, 0)(true)(false)
// You made a mistake at this point.
metamacro_if_eq0_0(true)(false)
true metamacro_consume_(false)
true
After the second round of concatenation, true becomes the argument to metamacro_if_eq0_0(). The argument(s) to that macro is/are left in its place. metamacro_consume_() takes any numer of arguments and resolves to nothing.
In my inno setup script there is a [code] section and I need to add some code to:
Open an xml file
then add a single node in a specific place
Save the file back to the hard drive
I need to be able to edit a file called config.xml in \documents\docotype
in the file there is some code like this:
<References>
<ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<string>System.dll</string>
<string>System.Core.dll</string>
<string>System.Drawing.dll</string>
<string>System.Windows.Forms.dll</string>
<string>System.XML.dll</string>
</ArrayOfString>
</References>
I need it to look like this:
<References>
<ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<string>System.dll</string>
<string>System.Core.dll</string>
<string>System.Drawing.dll</string>
<string>System.Windows.Forms.dll</string>
<string>System.XML.dll</string>
<string>C:\\bin\Custom\cutty109.dll</string>
</ArrayOfString>
</References>
So really I just need to add the following line into the file in the 'ArrayOfString' section
<string>C:\\bin\Custom\cutty109.dll</string>
I'm sure this must be possible but I have no clue how..
Thanks
Please refer the CodeAutomation.iss example provided along with inno install. And use this code instead the original code under the 'Modify the XML document' section.
{ Modify the XML document }
NewNode := XMLDoc.createElement('string');
XMLDoc.setProperty('SelectionLanguage', 'XPath');
RootNode := XMLDoc.selectSingleNode('//References/ArrayOfString');
RootNode.appendChild (NewNode);
RootNode.lastChild.text :='C:\\bin\Custom\cutty109.dll';
{ Save the XML document }
I assume you really need some dynamic way to add to this config file, if not then of course overriding the old one is the simplest method.
To dynamically add sections to a config file, you have some options:
You can create your own command line utility (exe or script) that does the file manipulation and call that utility in the [Run] section of your install script. This could look something like this:
In the [Files] section, you'll have one line for your utility:
Source: "myUtil.exe"; DestDir: "{app}"
In the [Run] section, you'll have one line for each manipulation you need to do in your config, like this:
FileName: "{app}\myUtil.exe"; Parameters: "/addSection:"
OR
You can use Pascal scripting to manipulate your config file. You can create a Pascal that uses CreateOleObject to call msxml.dll for XML the file manipulation. Then, in your [Files] section you can use AfterInstall to to call your Pascal function, like this:
Source: "myFileThatNeedsConfigManipulation.dll"; DestDir: ... ;
AfterInstall: MyPascalFunctionThatDoesTheManipulation
Try something like this:
Dim sXPath : sXPath = "/configuration/References/ArrayOfString"
Dim sAdd : sAdd = "C:\\bin\Custom\cutty109.dll"
Dim sElm : sElm = "string"
Dim sFSpec : sFSpec = resolvePath( "..\data\config.xml" )
Dim oXDoc : Set oXDoc = CreateObject( "Msxml2.DOMDocument" )
oXDoc.setProperty "SelectionLanguage", "XPath"
oXDoc.async = False
oXDoc.load sFSpec
If 0 = oXDoc.ParseError Then
WScript.Echo sFSpec, "looks ok"
Dim ndFnd : Set ndFnd = oXDoc.selectSingleNode( sXPath )
If ndFnd Is Nothing Then
WScript.Echo "|", sXPath, "| not found"
Else
WScript.Echo "found |" & ndFnd.tagName & "|"
Dim ndNew : Set ndNew = oXDoc.createElement( sElm )
ndNew.appendChild oXDoc.createTextNode( sAdd )
ndFnd.appendChild ndNew
WScript.Echo "After appending:"
WScript.Echo oXDoc.xml
oXDoc.Save Replace( sFSpec, ".xml", "-2.xml" )
End If
Else
WScript.Echo oXDoc.ParseError.Reason
End If
The steps:
create a Msxml2.DOMDocument
use XPath to find the node to change
create a now string element and append the text
append the new node to the found node
save the modified XML
I am trying to read this XML document.
An excerpt:
<datafile xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="wiitdb.xsd">
<WiiTDB version="20100217113738" games="2368"/>
<game name="Help Wanted: 50 Wacky Jobs (DEMO) (USA) (EN)">
<id>DHKE18</id>
<type/>
<region>NTSC-U</region>
<languages>EN</languages>
<locale lang="EN">
<title>Help Wanted: 50 Wacky Jobs (DEMO)</title>
<synopsis/>
</locale>
<developer>HUDSON SOFT CO., LTD.</developer>
<publisher>Hudson Entertainment, Inc.</publisher>
<date year="2009" month="" day=""/>
<genre>party</genre>
<rating type="ESRB" value="E10+">
<descriptor>comic mischief</descriptor>
<descriptor>mild cartoon violence</descriptor>
<descriptor>mild suggestive themes</descriptor>
</rating>
<wi-fi players="0"/>
<input players="2">
<control type="wiimote" required="true"/>
<control type="nunchuk" required="true"/>
</input>
<rom version="" name="Help Wanted: 50 Wacky Jobs (DEMO) (USA) (EN).iso" size="4699979776"/>
</game>
So far I have this:
Dim doc as XPathDocument
Dim nav as XPathNavigator
Dim iter as XPathNodeIterator
Dim lstNav As XPathNavigator
Dim iterNews As XPathNodeIterator
doc = New XPathDocument("wiitdb.xml")
nav = doc.CreateNavigator
iter = nav.Select("/WiiTDB/game") 'Your node name goes here
'Loop through the records in that node
While iter.MoveNext
'Get the data we need from the node
lstNav = iter.Current
iterNews = lstNav.SelectDescendants(XPathNodeType.Element, False)
'Loop through the child nodes
txtOutput.Text = txtOutput.Text & vbNewLine & iterNews.Current.Name & ": " & iterNews.Current.Value
End While
It just skips the "While iter.MoveNext" part of the code. I tries it with a simple XML file, and it works fine.
I think your XPath query is off. WiiTDB is a closed node, so you need to look for /datafile/game or //game.
Use the System.Xml.Serialization namespace instead: create a dedicated, serializable class to hold the data you wish to load and define shared serialize / deserialize functions with strongly typed arguments to do the work for you.
As the structure of the new classes will closely follow that of your XML data, there should be no confusion as to which data is located where within a run time instance.
See my answer here for an idea of how to create a class from an example XML file.