Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: XML file problem



Hi,

It's mostly a good idea to use xPath if you now the structure of your XML. From the found path you can process.

So you could use
"<?xml version=\"1.0\" encoding=\"iso-8859-1\" ?>
<myxml>
	<child>
			<data1><![CDATA[xxxx]]></data1>
			<data2>yyyy</data2>
			<data3>zzzz</data3>
	</child>	
</myxml>
"

set myXML to XMLOpen the result
set theRoot to XMLRoot myXML

set dataList to {}
set childNode to XMLXPath theRoot with "child"
repeat with c from 1 to (XMLCount of childNode)
	(*
	Note: an "empty" node like:
	<child>
	</child>	
	may have a count of 1 as well and could return a "return"
	{"
	"}
	to avoid that empty nodes should look like
	<child/>
	or "returns" should be deleted before processing the XML
	*)
	try
		set end of dataList to XMLGetText (XMLChild childNode index c)
	end
end repeat

XMLClose myXML
return dataList

Regards
Andreas


On 18.02.2007, at 13:04, Jasper Van Proeyen wrote:

Everybody, thanks for your help. I've finally managed to get some data out of my XML file.

I only don't see how to get all the children's data (data1, data2 and data3) seperately in an array.

Now I just use:

set theChild to XMLChild theRoot index 1
set data1 to XMLGetText (XMLXPath theChild with "data1")
set data2 to XMLGetText (XMLXPath theChild with "data2")
set data3 to XMLGetText (XMLXPath theChild with "data3")

... which does the same thing, only in 3 variables, but what if I don't exactly know how many children there are and I want to assemble all their values in one array?
Never mind, I don't have to do this myself, but maybe it's a useful question for the rest of the list...


Thanks again,
Jasper.

––––––––
email@hidden
http://jasper.vanproeyen.be/blog/
http://homepage.mac.com/trianglejuice/


On 17 Feb 2007, at 05:29PM, Andreas Kiel wrote:

Have a look at the Satimage XMLlib osax, this works flawless even with huge XMLs - at least for me.
data1 seems to be a comment and is not closed, anyway


so data values (using XMLlib osax) will be
"<?xml version=\"1.0\" encoding=\"iso-8859-1\" ?>
<myxml>
	<child>
			<data1><![CDATA[xxxx]]></data1>
			<data2>yyyy</data2>
			<data3>zzzz</data3>
	</child>	
</myxml>
"

set myXML to XMLOpen the result
set theRoot to XMLRoot myXML
set childData to XMLGetText (XMLXPath theRoot with "child")
XMLClose myXML

--> xxxxyyyyzzzz


Regards Andreas

On 17.02.2007, at 18:10, Jasper Van Proeyen wrote:

Hi list,

I have an XML file with the following structure:

<?xml version="1.0" encoding="iso-8859-1" ?>
<myxml>
	<child>
		<data1><![CDATA[xxxx]]</data1>
		<data2>yyyy</data2>
		<data3>zzzz</data3>
	</child>	
</myxml>

Given that the XML file is generated online: can I just use the following line to store the complete contents of the XML file in a variable and somehow still access the "xxxx", "yyyy" and "zzzz" strings?
set theXML to do shell script "curl --silent 'http://myserver.com/ generatexml.php" (output of the URL is an XML file)


If so, how can I store the 3 string values into an array (or 3 seperate values - it doesn't matter actually)?
If not, what's the best way to access these strings then?


I've tried via "System Events", but that didn't work:
set valueY to value of XML element "data2" of XML elements of XML element "child" of XML element "myxml" of XML element 1 of contents of theXML (gives a very strange "Can't make \"myxml\" into type integer" error)


Any help would be appreciated.

Regards,
Jasper.

––––––––
email@hidden
http://jasper.vanproeyen.be/blog/
http://homepage.mac.com/trianglejuice/


_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-studio mailing list (Applescript- email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/applescript-studio/ email@hidden


This email sent to email@hidden



Andreas Kiel Spherico Nelkenstr. 25 D-76135 Karlsruhe Tel.: +49 (0)721 183 9753 eFax: +1 650 897 8094

eMail: email@hidden
http://spherico.com/filmtools -- workflow tools for FCP

Latest Projects/News:
Apple recommends BWF2XML as tool for Broadcast Wave Files when working with with film/HD and external audio.
Sound Devices recommends BWF2XML as tool for Broadcast Wave Files and FCP.
ARRI Film & TV chooses customized version of TitleExchange for subtitling film and HD projects with FCP.
BWF2XML is used within David Fincher's "Zodiac" production for sound workflow.
Being part of a technology award @ Daimler-Chrysler for "Best Technical Innovation" - testing virtual cars using my spherical video productions and concepts. So feel yourself and let others feel safe when driving a Daimler-Chrysler van - we tested the visual ergonomics with real world "content" in a virtual space.
Ripple Training chooses TitleExchange Pro for video subtitling with their latest DVDSP training DVD (http://www.rippletraining.com/movies/ Free%20Downloads/dvdsp_subsanity_960.mov)
Sony US chooses BWF2XML for music video production workflow.
Pixar chooses XML2Text for film production workflow.
Apple Computer chooses BWF2XML for whatever.
Adidas Japan chooses TitleExchange Pro for video subtitling.
Haxan Films, the creators of the "Blair Witch Project", successfully used BWF2XML for their new project: "Altered".
BBC/HBO production uses audio workflow tools from Spherico for BWF - http://www.hbo.com/events/rome/index.html
Norway TV chooses special version of XML2Text for broadcast organization.




_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-studio mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/applescript-studio/email@hidden

This email sent to email@hidden
References: 
 >XML file problem (From: Jasper Van Proeyen <email@hidden>)
 >Re: XML file problem (From: Jasper Van Proeyen <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.