Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从VBscript中的标记解析XML字符串_Xml_String_Parsing_Vbscript - Fatal编程技术网

从VBscript中的标记解析XML字符串

从VBscript中的标记解析XML字符串,xml,string,parsing,vbscript,Xml,String,Parsing,Vbscript,我在解析XML中的字符串时遇到了一些问题。下面是我的一个标签示例: <author> {"picture":"http:\/\/images.ak.instagram.com\/profiles\/profile_315469453_75sq_1381947801.jpg","name":"Natural Places And Views","username":"alhamadikh","link":"http:\/\/instagram.com\/alhamadikh"} &

我在解析XML中的字符串时遇到了一些问题。下面是我的一个标签示例:

<author>   {"picture":"http:\/\/images.ak.instagram.com\/profiles\/profile_315469453_75sq_1381947801.jpg","name":"Natural Places And Views","username":"alhamadikh","link":"http:\/\/instagram.com\/alhamadikh"}
</author>
以下是我试图提取作者内部图片的内容(未成功):

任何帮助或建议都将不胜感激,我已经在谷歌上搜索了几个小时,似乎找不到正确的答案。我还使用VBscript作为语言来提取信息


谢谢大家!

autor节点的.text就是:text。您不能使用XML进一步解析它。可以使用RegExp剪切/拆分带引号的键值对:

选项显式

Dim sAT : sAT =   "    {""picture"":""http:\/\/images.ak.instagram.com\/profiles\/profile_315469453_75sq_1381947801.jpg"",""name"":""Natural Places And Views"",""username"":""alhamadikh"",""link"":""http:\/\/instagram.com\/alhamadikh""}"
Dim reX : Set reX = New RegExp
reX.Global  = True
reX.Pattern = """([^""]+)"":""([^""]+)"""
Dim oMTS : Set oMTS = reX.Execute(sAT)
Dim oMT
For Each oMT In oMTS
    WScript.Echo oMT.SubMatches(0)
    WScript.Echo " ", oMT.SubMatches(1)
Next
输出:

cscript 22050687.vbs
picture
  http:\/\/images.ak.instagram.com\/profiles\/profile_315469453_75sq_1381947801.jpg
name
  Natural Places And Views
username
  alhamadikh
link
  http:\/\/instagram.com\/alhamadikh

为了进一步处理,最好将键值对放入字典。

正如@KekuSemau所指出的,
标记中的文本是JSON,而不是XML,因此不能使用XPath来选择图像URL。不过,如果只想从JSON对象提取一个URL,则不一定需要一个完整的JSON解析器。只要需求不变得更复杂,正则表达式就可以满足这一要求

Set re=New RegExp
re.Pattern=“”图片”“:”“(.*)”
对于重新执行中的每个m(x.SelectSingleNode(“作者”).text)
WScript.Echo m.Submatches(0)
下一个

位于XML节点内部。在vbscript中处理它(完全成熟)似乎并不太容易-啊哈!谢谢你的解释。我将尝试看看开发人员是否可以将“author”XMLnode的JSON部分进一步划分为他们自己的节点。感谢您抽出时间回答我的问题!
Dim sAT : sAT =   "    {""picture"":""http:\/\/images.ak.instagram.com\/profiles\/profile_315469453_75sq_1381947801.jpg"",""name"":""Natural Places And Views"",""username"":""alhamadikh"",""link"":""http:\/\/instagram.com\/alhamadikh""}"
Dim reX : Set reX = New RegExp
reX.Global  = True
reX.Pattern = """([^""]+)"":""([^""]+)"""
Dim oMTS : Set oMTS = reX.Execute(sAT)
Dim oMT
For Each oMT In oMTS
    WScript.Echo oMT.SubMatches(0)
    WScript.Echo " ", oMT.SubMatches(1)
Next
cscript 22050687.vbs
picture
  http:\/\/images.ak.instagram.com\/profiles\/profile_315469453_75sq_1381947801.jpg
name
  Natural Places And Views
username
  alhamadikh
link
  http:\/\/instagram.com\/alhamadikh