I am new to AJAX I have parsed general XML through jquery, but XML did not work with namespace can go. I have searched the web and I have very little resources. I found it is a post in Stakeoverflow but it is not working for me
Here is part of the XML file . Suppose I need a number of years from XML data. How do I get it?
& lt; Aves: Sunset & gt; & Lt; Aws: year number = "2011" /> & Lt; Aws: month number = "3" text = "march" abbrv = "mar" /> & Lt; Aws: day number = "27" text = "sunday" abbrv = "sun" /> & Lt; Aws: hour number = "7" hours -24 = "19" /> & Lt; Aws: minute number = "10" /> & Lt; Aws: second number = "28" /> & Lt; Aws: am-pm abbrv = "pm" /> & Lt; Aws: timezone offset = "-5" text = "central daylight time (USA)" abbrv = "CDT" /> & Lt; / AWS: Sunset & gt; Awaiting your response Thank you!
I recommend using a real namespace-aware XML parser if all possibly, especially when external services. There is no guarantee that the name space prefix will be constant with time, for example.
Most JavaScript DOM parsers will contain getElementsByTagNameNS () , which will allow you to find the real elements
var namespace = 'http: // Aws This process may look like something, assuming that your data was in xml_file . .example.com / '; Var parser = new DOMParser (); // WebKit, IE has its var xml = parser.parseFromString (xml_file, "text / xml"); Var year = xml.getElementsByTagNameNS (namespace, 'year') [0]; // First AOS returns: year element var year_value = year.getAttribute ('number');
Comments
Post a Comment