Xml属性无法正常工作如何获取 [英] Xml attribute not working properly how to get

查看:83
本文介绍了Xml属性无法正常工作如何获取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  dim  objXMLElement1  As  XmlNode 
dim doc As XmlDocument
dim objXMLAttribute < span class =code-keyword> As XmlAttribute
dim objXMLElement As XmlNode

objXMLElement1 = doc.CreateElement( Country
objXMLElement1.InnerText = 英国

objXMLAttribute = doc.CreateAttribute ( 代码
objXMLAttribute.Value = GBR
objXMLElement1.Attributes.Append(objXMLAttribute)

objXMLElement.AppendChild(objXMLElement1)

objXMLElement1 = doc.CreateElement( Country
objXMLElement1.InnerText = < span class =code-string> united kingdom

objXMLAttribute = doc.CreateAttribute( 代码
objXMLAttribute.Value = GBR
objXMLElement1.Attributes.Append(objXMLAttribute)

objXMLElement.AppendChild(objXMLElement1)





以上代码赠送



 <  国家   代码  =  GBR > 英国
< country > 英国



我的要求

 <  国家/地区   代码  =  GBR > 英国



当我删除上面的exces元素时它不起作用

如何解决这个问题,



提前感谢



我尝试了什么:



i我正在尝试上面的代码,但我没有得到我的要求当我删除多余的元素它不工作如何解决这个问题

解决方案

你的代码将无法正常工作 - 你会抛出许多问题和异常。看起来你从某个地方复制并粘贴不正确...



一旦代码被清理干净,它看起来很好:

< pre lang =vb> Dim objXMLElement1 As XmlNode
Dim doc As XmlDocument = XmlDocument

Dim objXMLAttribute As XmlAttribute

objXMLElement1 = doc.CreateElement( Country
objXMLElement1.InnerText = 英国

objXMLAttribute = doc.CreateAttribute( 代码
objXMLAttribute.Value = GBR
objXMLEle ment1.Attributes.Append(objXMLAttribute)

Console.WriteLine(objXMLElement1.OuterXml)



哪个输出:

 <  国家/地区   代码  =  GBR > 英国<   /国家 >  


dim objXMLElement1 As XmlNode
dim doc As XmlDocument
dim objXMLAttribute As XmlAttribute
dim objXMLElement As XmlNode

objXMLElement1 = doc.CreateElement("Country")
objXMLElement1.InnerText = "united kingdom"

objXMLAttribute = doc.CreateAttribute("Code")
objXMLAttribute.Value = "GBR"
objXMLElement1.Attributes.Append(objXMLAttribute)

objXMLElement.AppendChild(objXMLElement1)

objXMLElement1 = doc.CreateElement("Country")
objXMLElement1.InnerText = "united kingdom"

objXMLAttribute = doc.CreateAttribute("Code")
objXMLAttribute.Value = "GBR"
objXMLElement1.Attributes.Append(objXMLAttribute)

objXMLElement.AppendChild(objXMLElement1)



Above Code presented

<Country code="GBR">united kingdom
<country>United kingdom 


My requirement

<Country Code="GBR">united kingdom


when i am remove the above exces element it doesn't work
how to solve this problem,

thanks in advance

What I have tried:

i am trying above code , but i am not getting my requirement when i am remove excess element it doesn't working how to solve this problem

解决方案

Your code won't work as is - you have a number of issues and exceptions thrown. It looks like you have copied and paste incorrectly from somewhere...

Once the code is cleaned up, it looks fine:

Dim objXMLElement1 As XmlNode
Dim doc As XmlDocument = New XmlDocument

Dim objXMLAttribute As XmlAttribute

objXMLElement1 = doc.CreateElement("Country")
objXMLElement1.InnerText = "united kingdom"

objXMLAttribute = doc.CreateAttribute("Code")
objXMLAttribute.Value = "GBR"
objXMLElement1.Attributes.Append(objXMLAttribute)

Console.WriteLine(objXMLElement1.OuterXml)


Which outputs:

<Country Code="GBR">united kingdom</Country>


这篇关于Xml属性无法正常工作如何获取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆