• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Display XML data in a Dynamic Text box

New Here ,
Sep 30, 2022 Sep 30, 2022

Copy link to clipboard

Copied

Looking for help in an Adobe Animate HTML5 cavas project. I have a simple xml file that I would like the Amount number to populate a dynamic text box. The dynamic text instance name is DayAmount. 
XML code:

<Total>
<Amount>$62,000</Amount>
</Total>
 
Looking for help what code I would need to use to get the JS to display this number. 
TOPICS
Code , How to

Views

355

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 30, 2022 Sep 30, 2022

Copy link to clipboard

Copied

const xmlStr = '<Total><Amount>$62,000</Amount></Total>';
const parser = new DOMParser();
const doc = parser.parseFromString(xmlStr, "application/xml");

 

your_tf.text= doc.getElementsByTagName("Amount")[0].childNodes[0]);

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 30, 2022 Sep 30, 2022

Copy link to clipboard

Copied

Sorry, a clearer eplaination is the number in my XML file is a running total that always updating with a new total, I want to be able call to the actual XML file to to pull that number.  

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 30, 2022 Sep 30, 2022

Copy link to clipboard

Copied

your first post was clear, and clearly answered. your 2nd post is unclear.

 

exactly what do you mean?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 30, 2022 Sep 30, 2022

Copy link to clipboard

Copied

Thanks for the help, We have a xml file stored online that has a running total that is constantly updated throughout the day. The amount total changing/grows based on some back end adding/ programming. All i see or have access to is that number. What my hope is to be able to pull that number and display in an HTML5 ad. However, i have no clue if this possible and i dont exactly know how to code this. I have very basic knowledge of javascript and even less of coding within animate. Those few lines code is all that is in the XML file itself. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 30, 2022 Sep 30, 2022

Copy link to clipboard

Copied

add a component to your canvas project or add jquery some other way, and whenever you want to load that xml (eg, "amount.xml"), call startLoadF()

 

function startLoadF() {
loadXMLF('"amount.xml');
}

function loadXMLF(s){
$.ajax({
url: s,
dataType: 'text',
success: parseXMLF
});
}
function parseXMLF(data){
var xmlDoc = $.parseXML(data);
var $xml = $(xmlDoc);
your_tf.text = $xml.find("Total")[0].childNodes[1].childNodes[0];  // assuming your text field is your_tf

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 03, 2022 Oct 03, 2022

Copy link to clipboard

Copied

just making sure I am doing this correctly, I would just replace the  'amount.xml' with website xml location. for example:

function startLoadF() {
loadXMLF('https://website.com/file.xml ');
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 03, 2022 Oct 03, 2022

Copy link to clipboard

Copied

yes, but using a cross-domain load might tigger a browser error.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 03, 2022 Oct 03, 2022

Copy link to clipboard

Copied

Thanks for you help. I cant seem to get this to work or figured out. I'm sure there is a way to get this done, I just can't seem to get this to work even with all your help and code you have provided. Your time and help is very much appreciated. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 03, 2022 Oct 03, 2022

Copy link to clipboard

Copied

are you making a cross-domain (ie, the loading/requesting code is on your local computer or web site A and the to-be-loaded xml is on siteB) load?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 03, 2022 Oct 03, 2022

Copy link to clipboard

Copied

web site A and the to-be-loaded xml is on siteB

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 03, 2022 Oct 03, 2022

Copy link to clipboard

Copied

that's a problem (cross-domain loading). 

 

do you control website B, so you can allow cross domain loads?

 

or learn about jsonp,

 

https://www.w3schools.com/js/js_json_jsonp.asp#:~:text=JSONP%20stands%20for%20JSON%20with,instead%20....

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 03, 2022 Oct 03, 2022

Copy link to clipboard

Copied

I personally dont have control the xml file and how it was written. However, we do control the xml is on our server. This cross domain was one of my thoughts though because I display this xml Amount total on our website using Javascript and it works on most platforms except google chrome desktop. blocks which we think is cross domain related. We give this xml website link to our billboard vendors and they can pull this xml and use the number displayed. I dont know enough about this to make something like this work. The general idea was to attempt to display live data on a web ad. Making use of our live data in as many platforms as we can. How do i allow cross domain loads. I guess its a simple one line of code we need to add to our xml file. then again i have no clue what I'm talking about. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 03, 2022 Oct 03, 2022

Copy link to clipboard

Copied

LATEST

open your chrome developer console and you should be able to see a cors violation.

 

and no, it's not anything you add to your xml file.  you would add it to the web server hosting the xml file.

 

or in your canvas project use jsonp code.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines