我有這個代碼的XML文件:Visual Basic中解析XML文件中使用XmlDocument的
<?xml version='1.0' encoding='utf-8'?>
<widget id="PACKAGE_NAME" version="PROJECT_VERSION" xmlns="http://www.w3.org/ns/widgets" xmlns:gap="http://phonegap.com/ns/1.0">
<name>PROJECT_NAME</name>
<preference name="android-minSdkVersion" value="MIN_SDK" />
<preference name="android-versionCode" value="VERSION_CODE" />
<preference name="android-installLocation" value="INSTALL" />
<preference name="android-targetSdkVersion" value="TARGET_SDK" />
<preference name="orientation" value="ORIENTATION" />
<preference name="fullscreen" value="FULLSCREEN" />
</widget>
,我有這個變量:
Dim PackageName, ProjectName, ProjectVersion, VersionCode, MinSdk, TargetSdk, InstallLocation, Orientation, FullScreen As String
我使用此代碼來獲得項目名,包名和ProjectVersion:
Dim doc as XmlDocument = new XmlDocument()
doc.Load("config.xml")
Dim root As XmlElement = doc.DocumentElement
PackageName = root.GetAttribute("id")
ProjectVersion = root.GetAttribute("version")
ProjectName = root.GetElementsByTagName("name").Item(0).InnerText
但我不能得到這個值:
VersionCode = VERSION_CODE
MinSdk = MIN_SDK
TargetSdk = TARGET_SDK
FullScreen = FULLSCREEN
Orientation = ORIENTATION
謝謝:)
你嘗試過什麼嗎?所需值的xpath是非常基本的,你應該能夠對它們進行編碼。 –
@PankajJaju我編輯了我的問題:) –