Jump to content
Search Community

Accessing rawXML text data

funk247 test
Moderator Tag

Recommended Posts

I'm loading an XML file that follows this format, s'all working perfectly.

<?xml version="1.0" encoding="UTF-8"?>
<data>
	<LoaderMax name="PEDThumbs" load="true">
		<ImageLoader docTitle="Candidate Registration Form" url="data/images/pre/thumbs/Candidate Registration Form.png" file="data/files/pre/Candidate Registration Form.pdf">
			<docDesc><![CDATA[<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque nec rhoncus nisi. Quisque nec augue eu dui vestibulum blandit. Proin viverra turpis suscipit, vestibulum velit consectetur, ullamcorper dolor. Donec ornare facilisis nulla non elementum. Phasellus mattis nunc nisl. Nam elementum fermentum commodo. Cras et metus faucibus, cursus odio vel, sodales ante. Donec non odio vitae urna sodales blandit quis ac magna. Vivamus viverra laoreet ligula, nec fermentum augue condimentum eu.</p>
			<p>In vel congue mauris. Maecenas consequat tempor eros a scelerisque. Nulla facilisi. Donec id nisi vel odio iaculis eleifend in in lorem. Aliquam lorem tortor, commodo a pretium quis, laoreet nec odio. Phasellus posuere bibendum dolor vitae elementum. Vestibulum quis bibendum eros. Nulla et lacinia est.</p>
			<p><a href="www.google.com">This is a hyperlink, it takes the user to external websites</a></p>]]></docDesc>
		</ImageLoader>
		<ImageLoader docTitle="Example ID Verification Procedure" url="data/images/pre/thumbs/Example ID Verification Procedure.png" file="data/files/pre/Example ID Verification Procedure.pdf">
			<docDesc><![CDATA[<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque nec rhoncus nisi. Quisque nec augue eu dui vestibulum blandit. Proin viverra turpis suscipit, vestibulum velit consectetur, ullamcorper dolor. Donec ornare facilisis nulla non elementum. Phasellus mattis nunc nisl. Nam elementum fermentum commodo. Cras et metus faucibus, cursus odio vel, sodales ante. Donec non odio vitae urna sodales blandit quis ac magna. Vivamus viverra laoreet ligula, nec fermentum augue condimentum eu.</p>
			<p>In vel congue mauris. Maecenas consequat tempor eros a scelerisque. Nulla facilisi. Donec id nisi vel odio iaculis eleifend in in lorem. Aliquam lorem tortor, commodo a pretium quis, laoreet nec odio. Phasellus posuere bibendum dolor vitae elementum. Vestibulum quis bibendum eros. Nulla et lacinia est.</p>
			<p><a href="www.google.com">This is a hyperlink, it takes the user to external websites</a></p>]]></docDesc>
		</ImageLoader>
	</LoaderMax>
	<LoaderMax name="PEDImages" load="true">
	    <ImageLoader 
			url="data/images/pre/Candidate Registration Form.png">
		</ImageLoader>
		<ImageLoader 
			url="data/images/pre/Example ID Verification Procedure.png">
		</ImageLoader>
	</LoaderMax>
</data>

I'm trying to access the data held in docDesc in preperation for parsing it as HTML (hyperlinks are important), so I created an array called docDesc and attempt to fill it like so:

docDesc[i] = loadedThumbs[i].vars.rawXML.i.i;

and I instance it like this:

currentTitle = event.target.name; // equates to a numeric index that can be used to pick items out of an array
txt2.docIntro.text = String(docDesc[currentTitle]);

When I trace the array it returns as ' , '. Checking the contents of vars.rawXML.i.i in the debugger shows that loaderMax has picked up the content, so why has it not cast it to the array? Is there a limitation on the number of characters I can place into the array or have I made some other error?

Link to comment
Share on other sites

When I try to traverse the contents of docDesc like this it returns the full contents of the imageLoader node:

docDesc[i] = loadedThumbs[i].vars.rawXML.toString();

But accessing any sub-node of rawXML just returns an empty set. The annoying thing is I can see the data I want to access! Excuse the massive pic.

 

xmlList.jpg

docDesc[i] = loadedThumbs[i].vars.rawXML.i.i.toString();

Would evaluate to 

docDesc[i] = loadedThumbs[i].vars.rawXML.0.0.toString();

So why are the contents returning as empty? Not even a null object reference, just as empty. 

 

Sorry if I'm being a noob.

Link to comment
Share on other sites

Glad you sorted it out. You'll find it was happening because this:

loadedThumbs[i].vars.rawXML.i.i.toString();

will not evaluate, and will instead look for <i> nodes:

<root>
  <i>
    <i><- this one --></i>
  </i>
</root>

 
If I recall correctly, you might do it like this:

loadedThumbs[i].vars.rawXML.children()[i].children()[i].toString();
  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...