0
好的,因爲我最後一個關於這個問題的問題有點錯誤,我決定做一個更正確的新文件。如何讀命名空間的XML文件(VB.net)
我試着去閱讀,看起來像這樣一個XML文件:
<?xml version="1.0" encoding="utf-8"?>
<Document xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:iso:std:iso:20022:tech:xsd:pain.008.001.02">
<AllThingsInThisDocument>
<Headerstuff>
</Headerstuff>
<Reports>
<Report>
<Id>01</Id>
<Name>AA</Name>
</Report>
<Report>
<Id>02</Id>
<Name>BB</Name>
</Report>
</Reports>
</AllThingsInThisDocument>
</Document>
當我使用此代碼迴路的報告,它給了我沒有錯誤,但它給了我零;
Dim xmlr As XDocument = XDocument.Load("MyMxlFile.xml")
For Each report As XElement In xmlr.Descendants("Report")
'Do some cool stuff
Next
我發現它是xmlns="urn:iso:std:iso:20022:tech:xsd:pain.008.001.02"
,它給了我錯誤。如果我從xmlfile中刪除它,它會給我報告。
只是爲了測試,我試了兩個函數,一個刪除所有命名空間,一個將它們設置爲空白。我在循環之前運行了這些函數。這可以工作,但是當我嘗試將它保存爲新的xml文件時,會給我一個有關命名空間的錯誤。這真的感覺就是這樣做的錯誤方式。
我該如何閱讀這個名字空間的報告?