0
我讀包含這樣的標籤的XML:的XDocument,上面說一個節點是文本,但它是一個元素
<source><bpt id="1"><donottranslate></bpt><ph id="2">($ T_353_1 Parent ID $)</ph><ept id="1"></donottranslate></ept></source>
當讀取source
節點我得到這個節點類型是文本,但它應該是Element。 這是一個我正在接收的XML,我無法更改它。
你知道我該如何解決這個問題?
這是我的代碼:
XDocument doc = XDocument.Load(fileName, LoadOptions.PreserveWhitespace);
foreach (var elUnit in doc.Descendants("trans-unit"))
{
if (elUnit.AttributeString("translate").ToString() == "no")
{
foreach (var elSource in elUnit.Elements("source"))
{
string text = "";
foreach (var node in elSource.DescendantNodes().Where(n => XmlNodeType.Text == n.NodeType).ToList())
{
//When reading that "source" node, it enters inside this code
感謝
你的XML格式不正確formed-'dnt'和'bpt'相交海誓山盟。 – StuartLC