Hướng dẫn remove xml tag javascript - xóa thẻ xml javascript

Tôi đang làm việc trên Node XML Node. Tôi có vấn đề trong việc xóa nút cha mẹ với chính nút bên trong.

Tôi muốn xóa nút mẹ bằng một vài nút bên trong và giữ lại một số nút bên trong khác.

Nguồn của chuỗi XML:

 
 ***
       
            
       
       ***
       
           
               xxx
           
           
       
 ******
     
         
             xxx
         
                   
    
 

Đầu ra của tôi sẽ là



     
        xxx
     
      
 

   
         xxx
   
            


Có ai hỗ trợ tôi không?

Cảm ơn trước.

Đã hỏi ngày 6 tháng 6 năm 2015 lúc 7:25Jun 6, 2015 at 7:25

Hướng dẫn remove xml tag javascript - xóa thẻ xml javascript

Bạn có thể sử dụng phương thức thay thế trên nút cha của nút bạn muốn thay thế.

Vì vậy, bạn sẽ muốn thực hiện một người thay thế khi chuyển root trong bpoint của bạn với id 2 làm đối số đầu tiên và bpoint với id 1 là thứ hai

rootNode.replaceChild(bPoint2,bPoint1);

Thử nghiệm

var xml = 'xxxxxx'

//Create xml parser and parse to XMLDocument
var parser = new DOMParser();
var xmldoc = parser.parseFromString(xml,"text/xml");

//Get "root" node
var rootNode = xmldoc.querySelector("root");

//Would use id selectors but number ids are invalid selectors
var bPoint1 = xmldoc.querySelector("bPoint");
var bPoint2 = bPoint1.querySelector("bPoint");

//Replace bPoint 1 with bPoint2
rootNode.replaceChild(bPoint2,bPoint1);

//Get the new xml string
var newXml = (new XMLSerializer).serializeToString(xmldoc);

console.log(xmldoc);
document.body.innerText = newXml;

Đã trả lời ngày 6 tháng 6 năm 2015 lúc 7:45Jun 6, 2015 at 7:45

Patrick Evanspatrick EvansPatrick Evans

41.1k6 Huy hiệu vàng70 Huy hiệu bạc86 Huy hiệu đồng6 gold badges70 silver badges86 bronze badges

2

Phương thức này loại bỏ một thuộc tính XML khỏi phần tử hiện tại. Nó yêu cầu bạn sử dụng các phương thức XML khác để điều hướng qua tài liệu XML.

Cú pháp

XML.removeAttribute( AttributeName );

Tranh luận

Đối số sau đây là hợp lệ cho phương pháp này.

Tranh luậnLoại dữ liệuSự mô tả
AttributionNameSợi dâyThis argument specifies the text string you want the script to use as the XML attribute name. The string argument must contain characters valid for an XML element( for example, the string cannot include the characters< or >).

Trả về giá trị

Một đối tượng XML hoặc null.

Nếu thành công, phương thức trả về phần tử XML được cập nhật. Nếu không, nó trả lại null.

Abe ¶

1 năm trướcStrip HTML and PHP tags from a string

Tiến sĩ Gianluigi " Zane "Zanettini ¶

stever at starburstpublishing dot com dot au ¶

Hi. I made a function that removes the HTML tags along with their contents:

Function:
function strip_tags_content($text, $tags = '', $invert = FALSE) { preg_match_all('/<(.+?)[\s]*\/?[\s]*>/si', trim($tags), $tags);
 
$tags = array_unique($tags[1]);

      if(

is_array($tags) AND count($tags) > 0) {
    if(
$invert == FALSE) {
      return
preg_replace('@<(?!(?:'. implode('|', $tags) .')\b)(\w+)\b.*?>.*?@si', '', $text);
    }
    else {
      return
preg_replace('@<('. implode('|', $tags) .')\b.*?>.*?@si', '', $text);
    }
  }
  elseif(
$invert == FALSE) {
    return
preg_replace('@<(\w+)\b.*?>.*?@si', '', $text);
  }
  return
$text;
}
?>

Sample text:
$text = 'sample text with
tags
';

Result for strip_tags($text):
sample text with tags

Result for strip_tags_content($text):
text with

Result for strip_tags_content($text, ''):
sample text with

Result for strip_tags_content($text, '', TRUE);
text with

tags

I hope that someone is useful :)

BZPlan tại Web Dot de ¶

10 năm trước

a HTML code like this:



     
        xxx
     
      
 

   
         xxx
   
            


0



     
        xxx
     
      
 

   
         xxx
   
            


1



     
        xxx
     
      
 

   
         xxx
   
            


2



     
        xxx
     
      
 

   
         xxx
   
            


3



     
        xxx
     
      
 

   
         xxx
   
            


4



     
        xxx
     
      
 

   
         xxx
   
            


5



     
        xxx
     
      
 

   
         xxx
   
            


6



     
        xxx
     
      
 

   
         xxx
   
            


7



     
        xxx
     
      
 

   
         xxx
   
            


8

Doug tại khai thác

7 năm trước



     
        xxx
     
      
 

   
         xxx
   
            


9

rootNode.replaceChild(bPoint2,bPoint1);
0

rootNode.replaceChild(bPoint2,bPoint1);
1

rootNode.replaceChild(bPoint2,bPoint1);
2

rootNode.replaceChild(bPoint2,bPoint1);
3

rootNode.replaceChild(bPoint2,bPoint1);
4

rootNode.replaceChild(bPoint2,bPoint1);
5

rootNode.replaceChild(bPoint2,bPoint1);
6

rootNode.replaceChild(bPoint2,bPoint1);
7

Abe ¶

1 năm trước

rootNode.replaceChild(bPoint2,bPoint1);
8

rootNode.replaceChild(bPoint2,bPoint1);
9

var xml = 'xxxxxx'

//Create xml parser and parse to XMLDocument
var parser = new DOMParser();
var xmldoc = parser.parseFromString(xml,"text/xml");

//Get "root" node
var rootNode = xmldoc.querySelector("root");

//Would use id selectors but number ids are invalid selectors
var bPoint1 = xmldoc.querySelector("bPoint");
var bPoint2 = bPoint1.querySelector("bPoint");

//Replace bPoint 1 with bPoint2
rootNode.replaceChild(bPoint2,bPoint1);

//Get the new xml string
var newXml = (new XMLSerializer).serializeToString(xmldoc);

console.log(xmldoc);
document.body.innerText = newXml;
0

rootNode.replaceChild(bPoint2,bPoint1);
7

Tiến sĩ Gianluigi " Zane "Zanettini ¶

7 năm trước

var xml = 'xxxxxx'

//Create xml parser and parse to XMLDocument
var parser = new DOMParser();
var xmldoc = parser.parseFromString(xml,"text/xml");

//Get "root" node
var rootNode = xmldoc.querySelector("root");

//Would use id selectors but number ids are invalid selectors
var bPoint1 = xmldoc.querySelector("bPoint");
var bPoint2 = bPoint1.querySelector("bPoint");

//Replace bPoint 1 with bPoint2
rootNode.replaceChild(bPoint2,bPoint1);

//Get the new xml string
var newXml = (new XMLSerializer).serializeToString(xmldoc);

console.log(xmldoc);
document.body.innerText = newXml;
2

var xml = 'xxxxxx'

//Create xml parser and parse to XMLDocument
var parser = new DOMParser();
var xmldoc = parser.parseFromString(xml,"text/xml");

//Get "root" node
var rootNode = xmldoc.querySelector("root");

//Would use id selectors but number ids are invalid selectors
var bPoint1 = xmldoc.querySelector("bPoint");
var bPoint2 = bPoint1.querySelector("bPoint");

//Replace bPoint 1 with bPoint2
rootNode.replaceChild(bPoint2,bPoint1);

//Get the new xml string
var newXml = (new XMLSerializer).serializeToString(xmldoc);

console.log(xmldoc);
document.body.innerText = newXml;
3

var xml = 'xxxxxx'

//Create xml parser and parse to XMLDocument
var parser = new DOMParser();
var xmldoc = parser.parseFromString(xml,"text/xml");

//Get "root" node
var rootNode = xmldoc.querySelector("root");

//Would use id selectors but number ids are invalid selectors
var bPoint1 = xmldoc.querySelector("bPoint");
var bPoint2 = bPoint1.querySelector("bPoint");

//Replace bPoint 1 with bPoint2
rootNode.replaceChild(bPoint2,bPoint1);

//Get the new xml string
var newXml = (new XMLSerializer).serializeToString(xmldoc);

console.log(xmldoc);
document.body.innerText = newXml;
4

rootNode.replaceChild(bPoint2,bPoint1);
7

Abe ¶

1 năm trước

var xml = 'xxxxxx'

//Create xml parser and parse to XMLDocument
var parser = new DOMParser();
var xmldoc = parser.parseFromString(xml,"text/xml");

//Get "root" node
var rootNode = xmldoc.querySelector("root");

//Would use id selectors but number ids are invalid selectors
var bPoint1 = xmldoc.querySelector("bPoint");
var bPoint2 = bPoint1.querySelector("bPoint");

//Replace bPoint 1 with bPoint2
rootNode.replaceChild(bPoint2,bPoint1);

//Get the new xml string
var newXml = (new XMLSerializer).serializeToString(xmldoc);

console.log(xmldoc);
document.body.innerText = newXml;
6

var xml = 'xxxxxx'

//Create xml parser and parse to XMLDocument
var parser = new DOMParser();
var xmldoc = parser.parseFromString(xml,"text/xml");

//Get "root" node
var rootNode = xmldoc.querySelector("root");

//Would use id selectors but number ids are invalid selectors
var bPoint1 = xmldoc.querySelector("bPoint");
var bPoint2 = bPoint1.querySelector("bPoint");

//Replace bPoint 1 with bPoint2
rootNode.replaceChild(bPoint2,bPoint1);

//Get the new xml string
var newXml = (new XMLSerializer).serializeToString(xmldoc);

console.log(xmldoc);
document.body.innerText = newXml;
7

var xml = 'xxxxxx'

//Create xml parser and parse to XMLDocument
var parser = new DOMParser();
var xmldoc = parser.parseFromString(xml,"text/xml");

//Get "root" node
var rootNode = xmldoc.querySelector("root");

//Would use id selectors but number ids are invalid selectors
var bPoint1 = xmldoc.querySelector("bPoint");
var bPoint2 = bPoint1.querySelector("bPoint");

//Replace bPoint 1 with bPoint2
rootNode.replaceChild(bPoint2,bPoint1);

//Get the new xml string
var newXml = (new XMLSerializer).serializeToString(xmldoc);

console.log(xmldoc);
document.body.innerText = newXml;
8

var xml = 'xxxxxx'

//Create xml parser and parse to XMLDocument
var parser = new DOMParser();
var xmldoc = parser.parseFromString(xml,"text/xml");

//Get "root" node
var rootNode = xmldoc.querySelector("root");

//Would use id selectors but number ids are invalid selectors
var bPoint1 = xmldoc.querySelector("bPoint");
var bPoint2 = bPoint1.querySelector("bPoint");

//Replace bPoint 1 with bPoint2
rootNode.replaceChild(bPoint2,bPoint1);

//Get the new xml string
var newXml = (new XMLSerializer).serializeToString(xmldoc);

console.log(xmldoc);
document.body.innerText = newXml;
9

rootNode.replaceChild(bPoint2,bPoint1);
7

Tiến sĩ Gianluigi " Zane "Zanettini ¶

stever at starburstpublishing dot com dot au ¶

XML.removeAttribute( AttributeName );
1

XML.removeAttribute( AttributeName );
2

XML.removeAttribute( AttributeName );
3

XML.removeAttribute( AttributeName );
4

rootNode.replaceChild(bPoint2,bPoint1);
7

6 năm trước

Roger Dot Keulen tại Vaimo Dot Com ¶

XML.removeAttribute( AttributeName );
6

XML.removeAttribute( AttributeName );
7

rootNode.replaceChild(bPoint2,bPoint1);
7

3 năm trước

1 năm trước

XML.removeAttribute( AttributeName );
9

Hi. I made a function that removes the HTML tags along with their contents: 0

Hi. I made a function that removes the HTML tags along with their contents: 1

rootNode.replaceChild(bPoint2,bPoint1);
7

Tiến sĩ Gianluigi " Zane "Zanettini ¶

stever at starburstpublishing dot com dot au ¶

Hi. I made a function that removes the HTML tags along with their contents: 3

Hi. I made a function that removes the HTML tags along with their contents: 4

rootNode.replaceChild(bPoint2,bPoint1);
7

6 năm trước

Roger Dot Keulen tại Vaimo Dot Com ¶

Hi. I made a function that removes the HTML tags along with their contents: 6

Hi. I made a function that removes the HTML tags along with their contents: 7

Hi. I made a function that removes the HTML tags along with their contents: 8

Hi. I made a function that removes the HTML tags along with their contents: 9

3 năm trước

CEO tại Carpool2camp Dot org ¶

Function:
function strip_tags_content($text, $tags = '', $invert = FALSE) { preg_match_all('/<(.+?)[\s]*\/?[\s]*>/si', trim($tags), $tags);
 
$tags = array_unique($tags[1]);
0

Function:
function strip_tags_content($text, $tags = '', $invert = FALSE) { preg_match_all('/<(.+?)[\s]*\/?[\s]*>/si', trim($tags), $tags);
 
$tags = array_unique($tags[1]);
1

Function:
function strip_tags_content($text, $tags = '', $invert = FALSE) { preg_match_all('/<(.+?)[\s]*\/?[\s]*>/si', trim($tags), $tags);
 
$tags = array_unique($tags[1]);
2

Function:
function strip_tags_content($text, $tags = '', $invert = FALSE) { preg_match_all('/<(.+?)[\s]*\/?[\s]*>/si', trim($tags), $tags);
 
$tags = array_unique($tags[1]);
3

Function:
function strip_tags_content($text, $tags = '', $invert = FALSE) { preg_match_all('/<(.+?)[\s]*\/?[\s]*>/si', trim($tags), $tags);
 
$tags = array_unique($tags[1]);
4

Function:
function strip_tags_content($text, $tags = '', $invert = FALSE) { preg_match_all('/<(.+?)[\s]*\/?[\s]*>/si', trim($tags), $tags);
 
$tags = array_unique($tags[1]);
5

Function:
function strip_tags_content($text, $tags = '', $invert = FALSE) { preg_match_all('/<(.+?)[\s]*\/?[\s]*>/si', trim($tags), $tags);
 
$tags = array_unique($tags[1]);
6

rootNode.replaceChild(bPoint2,bPoint1);
7

13 năm trước

Trititaty ¶

Function:
function strip_tags_content($text, $tags = '', $invert = FALSE) { preg_match_all('/<(.+?)[\s]*\/?[\s]*>/si', trim($tags), $tags);
 
$tags = array_unique($tags[1]);
8

Cesar tại Nixar Dot org ¶

16 năm trước

Function:
function strip_tags_content($text, $tags = '', $invert = FALSE) { preg_match_all('/<(.+?)[\s]*\/?[\s]*>/si', trim($tags), $tags);
 
$tags = array_unique($tags[1]);
9

      if(0

rootNode.replaceChild(bPoint2,bPoint1);
7

D Mo ¶

Trititaty ¶

      if(2

      if(3

      if(4

      if(5

      if(6

rootNode.replaceChild(bPoint2,bPoint1);
7

Cesar tại Nixar Dot org ¶

7 năm trước

      if(8

      if(9

is_array($tags) AND count($tags) > 0) {
    if(
$invert == FALSE) {
      return
preg_replace('@<(?!(?:'. implode('|', $tags) .')\b)(\w+)\b.*?>.*?@si', '', $text);
    }
    else {
      return
preg_replace('@<('. implode('|', $tags) .')\b.*?>.*?@si', '', $text);
    }
  }
  elseif(
$invert == FALSE) {
    return
preg_replace('@<(\w+)\b.*?>.*?@si', '', $text);
  }
  return
$text;
}
?>

Sample text:
$text = 'sample text with

tags
';

Result for strip_tags($text):
sample text with tags

Result for strip_tags_content($text):
text with

Result for strip_tags_content($text, ''):
sample text with

Result for strip_tags_content($text, '', TRUE);
text with

tags

I hope that someone is useful :)

0

is_array($tags) AND count($tags) > 0) {
    if(
$invert == FALSE) {
      return
preg_replace('@<(?!(?:'. implode('|', $tags) .')\b)(\w+)\b.*?>.*?@si', '', $text);
    }
    else {
      return
preg_replace('@<('. implode('|', $tags) .')\b.*?>.*?@si', '', $text);
    }
  }
  elseif(
$invert == FALSE) {
    return
preg_replace('@<(\w+)\b.*?>.*?@si', '', $text);
  }
  return
$text;
}
?>

Sample text:
$text = 'sample text with

tags
';

Result for strip_tags($text):
sample text with tags

Result for strip_tags_content($text):
text with

Result for strip_tags_content($text, ''):
sample text with

Result for strip_tags_content($text, '', TRUE);
text with

tags

I hope that someone is useful :)

1

is_array($tags) AND count($tags) > 0) {
    if(
$invert == FALSE) {
      return
preg_replace('@<(?!(?:'. implode('|', $tags) .')\b)(\w+)\b.*?>.*?@si', '', $text);
    }
    else {
      return
preg_replace('@<('. implode('|', $tags) .')\b.*?>.*?@si', '', $text);
    }
  }
  elseif(
$invert == FALSE) {
    return
preg_replace('@<(\w+)\b.*?>.*?@si', '', $text);
  }
  return
$text;
}
?>

Sample text:
$text = 'sample text with
tags
';

Result for strip_tags($text):
sample text with tags

Result for strip_tags_content($text):
text with

Result for strip_tags_content($text, ''):
sample text with

Result for strip_tags_content($text, '', TRUE);
text with

tags

I hope that someone is useful :)

2