Adobe Dreamweaver Forums



Last 10 THreads :         pop up blocker jacking my login (Last Post : reelhero - Replies : 6 - Views : 7 )           »          RoboHelp 7 Skins (Last Post : HelpDev - Replies : 7 - Views : 35 )           »          Code that can effect two movie clips (Last Post : Alessandroy - Replies : 0 - Views : 1 )           »          Clock .getUTC not working (Last Post : kglad - Replies : 3 - Views : 4 )           »          problems linking PDFs (Last Post : Alan - Replies : 1 - Views : 2 )           »          Changing RadioButton Label (Last Post : justintoflex - Replies : 2 - Views : 5 )           »          Table Borders MIssing in JavaHelp (Last Post : soxmann - Replies : 3 - Views : 8 )           »          cfimage error (Last Post : masoud_amen - Replies : 2 - Views : 3 )           »          Dragging components (Last Post : hsfrey - Replies : 2 - Views : 5 )           »          Is file too large? (Last Post : tweaked_eye - Replies : 0 - Views : 1 )           »         


Home Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
User Info Statistics
Go Back   Adobe Dreamweaver Forums > Other Macromedia/Adobe Products > Flex
 
Tags:



Reply
  #1 (permalink)  
Old 12-03-2008, 05:32 PM
aharv1
 
Posts: n/a
Diggs:
Default Selecting XML Children with Namespaces

I am trying to select child nodes of an XML element that have a different
namespace from the parent, but xml.child(name) always returns null.

In the attached code, londonList contains a single XML element and parisList
is empty. I can't figure out how to find the paris child, and have tried adding
the prefix to findParis (so it is "ff:b") as well as turning findParis into an
XML object with the name "b" and adding the ff namespace to it, then passing
that to child. Neither of those have worked.

Any help is appreciated.

var testXML:XML = <root
xmlns:ff="http://fakenamespace"><a>London</a><ff:b >Paris</ff:b></root>;

var findLondon:String = "a";
var findParis:String ="b";

var londonList:XMLList = testXML.child(findLondon);
var parisList:XMLList = testXML.child(findParis);



Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 12-03-2008, 09:13 PM
-Hob
 
Posts: n/a
Diggs:
Default Re: Selecting XML Children with Namespaces

You need to use a namespace object and an e4x expression. Your code will look
something like this:

var ns:Namespace = new Namespace("http://fakenamespace");
var parisList:XMLList = testXML.ns::b;

note the :: between the ns & the b. ns b is the value that you're trying to
match and putting the :: before it allows you to specify its namespace.

Reply With Quote
  #3 (permalink)  
Old 12-03-2008, 09:13 PM
aharv1
 
Posts: n/a
Diggs:
Default Re: Selecting XML Children with Namespaces

Unfortunately in my real scenario I don't know what the element will be called.
It could be in <foo> or <bar> etc, so I need to be able to use a variable (in
which the element name is set beforehand). With "::" I can't use a variable, so
textXML.ns::findParis looks for a "findParis" element and not "b".

That's why I'm trying to use testXML.child(findParis) because I can use a
variable. I just can't figure out how to make it incorporate the namespace as
well.


Reply With Quote


  #4 (permalink)  
Old 12-04-2008, 07:23 PM
aharv1
 
Posts: n/a
Diggs:
Default Re: Selecting XML Children with Namespaces

I figured out the solution. the child() method uses the default namespace to
search for the element name. Since I couldn't figure out how to specify a
different namespace in the method call, just set the default namespace before
you call child to the namespace of the element.



var testXML:XML =
<gg:root xmlns:gg="http://ggnamespace" xmlns:ff="http://fakenamespace">
<gg:a>London</gg:a>
<ff:b>Paris</ff:b>
</gg:root>;

var findLondon:String = "a"
var findParis:String ="b";

var ff:Namespace = new Namespace("http://fakenamespace");
var gg:Namespace = new Namespace("http://ggnamespace");

default xml namespace = gg;
var londonList:XMLList = testXML.child(findLondon);

default xml namespace = ff;
var parisList:XMLList = testXML.child(findParis);

Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



© Camley Interactive (camley.info) 2008 - all logos and images are copywrite their respective owners.
Proud member of the Camley Interactive Network
All times are GMT. The time now is 12:03 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.
Cheap Car Insurance - Compare Motor Insurance
Endsleigh Car Insurance Natwest Car Insurance
More Than Car Insurance Norwich Union Car Insurance
Prudential Car Insurance Zurich Car Insurance
Inactive Reminders By Mished.co.uk