-
.nextSibling?????? maybe
Lil Help?,
I am simply attempting to have a swf file pull content from an .xml file. I have had success pulling "attributes" but I would like to pull the content from "nodes". I think that's the terminology.
Anywho, what I have going is 2 dynamic text boxs one labeled
tablename
and the second labeled
bodycopy
with the code provided below I get fine results within "tablename" however I get nothing in "bodycopy". Which leads me to believe the ".nextSibling" call/function whatever isn't working. Any help would be greatly appreciated.
[fla code]
tableXML = new XML();
tableXML.load("XMLcondensed.xml");
tableXML.onLoad = loadedXML;
tableXML.ignoreWhite = true;
function loadedXML() {
rootNode = tableXML.firstChild;
firstNode = rootNode.firstChild;
tablenameNode = firstNode.firstChild;
bodycopyNode = tablenameNode.nextSibling;
tablename = tablenameNode.nodeValue;
bodycopy = bodycopyNode.nodeValue;
}
stop();
[xml code]
<xml>
<tablename>yoyo</tablename>
<bodycopy>jojo</bodycopy>
</xml>
Thanks
-j-
-
Hi jubjub,
It sounds like you are using XML something like this:
PHP Code:
<myXML>
<first>
<tableName>My Table</tableName>
<bodyCopy>More text here, maybe?</bodyCopy>
</first>
</myXML>
If the above is true, then your code is doing well right up until you use nextSibling().
The issue is because the text ("My Table") is considered a child node... imagine the following document fragment:
PHP Code:
<sample>
This is a <b>Sample</b> of mixed content in <em>XML</em>
</sample>
In the above XML the "sample" node has a few child nodes:
- type=text, value = "{Enter}{Tab}This is a "
- type=element, name = "b" with a child that is of type text with a value of "Sample"
- type=text, value = " of mixed content in "
- type=element, name = "em" with a child that is of type text with a value of "XML"
- type=text, value = "{Enter}"
(you might not have the last child and the Enter and Tab in the first child depending on your IgnoreWhite settings).
Because the above is possible, the text of a node has to be represented as a child node with a special type (nodeType=3 I believe) that has a .value of the text.
What happened when you used nextSibling()? If you were using my "sample" then you would have ended up on the "b" element, but in the XML you are using it's not finding a sibling of the Text element, you need to use .parent.nextSibling() which will move the focus from the Text node back to the "tableName" node, and then find that node's nextSibling().
To help avoid this confusion I wrote some helper functions for the XML object that allowed you to do things like:
myXML.documentElement(); // select the root element
myElement.selectSingleNode("nodeName"); // select the first child with a specific name
myElement.selectNodes("nodeName"); // return an array of nodes that match the name
myElement.nodeText(); // return the text of this element
The last one was simply .firstChild.nodeValue with some error checking, although it could be extended to normalize multiple text-type children and return that...
Let me know if you would like these functions and I'll see if I can dig them up.
Hope this helps!
Tim Walters
Senior Developer
XML Evangelist
"XML isn't a language, it's a way of life!"
-
Actually my xml code is this.......
<myXML>
<tableName>My_Table</tableName>
<bodyCopy>More_text_here,_maybe?</bodyCopy>
</myXML>
I don't know why it didn't show here in this thread but this is the xml I am using. My understanding was that both "tableName" and "bodyCopy" were childNodes of "myXML" that was the reasoning behind the usage of "nextSibling". Any code you could dig up would be fantastic.
Thanks
-j-
-
maybe I need to be in enhanced mode.
testing....
<myXML>
<tableName>My_Table</tableName>
<bodyCopy>More_text_here,_maybe?</bodyCopy>
</first>
</myXML>
-
well I don't know why the board is stripping my xml tags but my xml appears just as you had written minus the "first" tags you had included. That's to say both "tablename" and "bodycopy" are opened and closed independently within the "xml" tags. I apologize for the confusion.
thanks
-j-
-
To post XML wrap it in [ php ] and [ /php ] (without spaces), then your XML would come out as:
PHP Code:
<myXML>
<tableName>My_Table</tableName>
<bodyCopy>More_text_here,_maybe?</bodyCopy>
</myXML>
Now, you are correct that the "tableName" tag is a child of "myXML", and the "bodyCopy" tag is also a child (and thus the nextSibling)... the issue is that the text "My_Table" is a CHILD of "tableName", perhaps if I show you a tree:
Code:
node: (name="MyXML", type=element)
node: (name="tableName", type=element)
node: (name=(null), type=text, value="My_Table")
node: (name="bodyCopy", type=element)
node: (name=(null), type=text, value="More_text_here,_maybe?")
I'll say it again to be very clear Text inside an element is a node of type 3 (text-node), and is a child of the element. To access the text of the surrounding parent's sibling you need to go:
.parent.nextSibling.firstChild.nodeValue
Hope this helps!
Tim Walters
Senior Developer
XML Evangelist
"XML isn't a language, it's a way of life!"
-
Sounds good. Thanks for your help.
-j-
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|