내 의도는 재귀 적 수단을 사용하여 주어진 xml의 모든 "텍스트 노드"를 찾는 것입니다. 예를 들어 입력 xml이 다음과 같으면
<foo>
<bar>
<a>1</a>
<b>2</b>
</bar>
</foo>
그럼 내가 찾으려 <a>
하고 <b>
그 후에 나는 다른 기능에 전달합니다. 관심있는 노드를 찾는 데 사용하는 코드는 다음과 같습니다.
xml = $.parseXML(MY_INPUT_XML);
nodesOfInterest = [];
var depthFirstTraversal = function ($root, callback) {
$root.children().each(function () {
depthFirstTraversal($(this), callback);
});
callback($root);
};
depthFirstTraversal($(xml).children(), function ($node) {
if ($node[0].childElementCount === 0) { //if it has no children then i want to store it
nodesOfInterest.push($node);
}
});
위는 대부분의 경우 예상대로 작동하지만 상위 노드에 일부 속성 또는 xsi 유형이 있으면 실패합니다. 예를 들어 아래가 내 입력 xml 인 경우 :
<soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<buyGuid>
<Context>
<INFO>
<buyGuidRequest>
<Property xsi:type="PostalAddress">
<address>Some address</address>
<postcode>0000</postcode>
</Property>
</buyGuidRequest>
</INFO>
</Context>
</buyGuid>
</soap:Body>
</soap:Envelope>
그것은의 아이들에게 통과하지 않습니다 <buyGuidRequest>
또는 <Property>
! 그러나 xsi:type
from <Property>
태그를 제거하면 Property의 모든 chidlren으로 올바르게 이동하여 Address와 zipCode를 찾습니다. 왜 이런 일이 발생하고 xsi : type이 깊이 순회에 어떤 영향을 미치는지 이해하지 못합니다. 누군가이 문제에 대해 밝힐 수 있습니까? 감사
입력 한 형식이 잘못되어 xsi 접두사를 인식하지 못하는 것 같습니다. 해당 동작은 속성을 제거 할 때 재현됩니다.
xmlns : xsi = "http://www.w3.org/2001/XMLSchema-instance"
요소에서
<비누 : 바디>
<soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<buyGuid>
<Context>
<INFO>
<buyGuidRequest>
<Property xsi:type="PostalAddress">
<address>Some address</address>
<postcode>0000</postcode>
</Property>
</buyGuidRequest>
</INFO>
</Context>
</buyGuid>
</soap:Body>
</soap:Envelope>
<soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<buyGuid>
<Context>
<INFO>
<buyGuidRequest>
<Property xsi:type="PostalAddress">
<address>Some address</address>
<postcode>0000</postcode>
</Property>
</buyGuidRequest>
</INFO>
</Context>
</buyGuid>
</soap:Body>
</soap:Envelope>
<soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<buyGuid>
<Context>
<INFO>
<buyGuidRequest>
<Property>
<address>Some address</address>
<postcode>0000</postcode>
</Property>
</buyGuidRequest>
</INFO>
</Context>
</buyGuid>
</soap:Body>
</soap:Envelope>
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다