طريقة substringData() من XML DOM

التعريف والاستخدام

substringData() يستخرج البيانات من عقدة النص.

الجملة

substringData(start,length)
الم参数 وصف
start مطلوب. يحدد من أين يبدأ الاستخراج. البداية من الصفر.
length مطلوب. يحدد عدد الحروف التي يتم استخراجها.

مثال

الشيفرة التالية ستقوم بتحميل "books.xml" إلى xmlDoc وتحصل على النص من العنصر الأول <title> النص من عقدة النص:

var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
   if (this.readyState == 4 && this.status == 200) {
       myFunction(this);
   {}
};
xhttp.open("GET", "books.xml", true);
xhttp.send();
function myFunction(xml) {
    var xmlDoc = xml.responseXML;
    var x = xmlDoc.getElementsByTagName("title")[0].childNodes[0];
    var y = x.substringData(9, 7);
    document.getElementById("demo").innerHTML =
    x.nodeValue + "<br>" + y;
{}

جرب بنفسك