2013-01-11 272 views
2

我有XML,看起來像刪除XML節點

<MeasureSet> 
    <MeasureSetType val_type="name">Variant</MeasureSetType> 
    <Measure> 
     <MeasureType val_type="name">single nucleotide variant</MeasureType> 
     <AttributeSet> 
     <MeasureAttributeType val_type="name">HGVS</MeasureAttributeType> 
     <Attribute>NM_000054.4:c.838dupT</Attribute> 
     </AttributeSet> 
     <Citation> 
     <CitationType val_type="name">general</CitationType> 
     <ID Source="PubMed">10820168</ID> 
     </Citation> 
     <Citation> 
     <CitationType val_type="name">general</CitationType> 
     <ID Source="PubMed" /> 
     </Citation> 
     <Citation> 
     <CitationType val_type="name">general</CitationType> 
     <ID Source="PubMed">9773787</ID> 
     </Citation> 
     <Citation> 
     <CitationType val_type="name">general</CitationType> 
     <ID Source="PubMed">18726898</ID> 
     </Citation> 
     <Citation> 
     <CitationType val_type="name">general</CitationType> 
     <ID Source="PubMed" /> 
     </Citation> 
    </Measure> 
    </MeasureSet> 

我想刪除具有引用/ ID/@來源=「考研」和引文/ ID是引用元素節點空

這僅刪除ID元素,但正確的人

SET @myBlob.modify('delete //Citation/ID[@Source = ''PubMed'' 
     and string-length(string(number(.))) = 0]') 

,這將刪除所有引用元素

SET @myBlob.modify('delete //Citation[ID/@Source = ''PubMed'' 
     and string-length(string(number(.))) = 0]') 

似乎應該有一個簡單的解決方案,我沒有打。有什麼建議麼?謝謝

回答

2

你的第二個檢查錯誤元素的長度 - 它看着(.),這裏是Citation元素(因爲它在Citation元素的謂詞中)。改用

SET @myBlob.modify(' 
     delete //Citation[ID/@Source = ''PubMed'' 
         and string-length(string(number(ID[1]))) = 0]') 

,我已經改變.ID[1]。需要[1],因爲「'number()' requires a singleton (or empty sequence)」。

+0

非常棒,正是我所需要的,非常感謝。 – user1969944