Posts: 51
Threads: 25
Joined: Oct 2014
Hello !
I have a string named XML that contains :
<Element>
<ID>16</ID>
<Date>2015-03-07T20:40:12</Date>
<Name>File1</Name>
<Link>http://youtube.com/</Link>
</Element>
<Element>
<ID>17</ID>
<Date>2015-03-07T20:40:12</Date>
<Name>File2</Name>
<Link>http://youtube.com/</Link>
</Element>
So basically, i have :
str XML
str file=File1
But now, i would like to "get" the ID of the File1, which is 16, through the XML string, but I don't figure how i could do it :/
I don't know how or if it's possible to search some specific characters in a string, so here i am, asking for help ^^
Could you help me please ? Thanks a lot !
Posts: 12,147
Threads: 143
Joined: Dec 2002
Macro
Macro2519
str XML=
;<elements>
;;;;<Element>
;;;;;;<ID>16</ID>
;;;;;;<Date>2015-03-07T20:40:12</Date>
;;;;;;<Name>File1</Name>
;;;;;;<Link>http://youtube.com/</Link>
;;;;</Element>
;;;;<Element>
;;;;;;;<ID>17</ID>
;;;;;;<Date>2015-03-07T20:40:12</Date>
;;;;;;<Name>File2</Name>
;;;;;;<Link>http://youtube.com/</Link>
;;;;</Element>
;</elements>
str file="File1"
str ID
IXml x._create
x.FromString(XML)
IXmlNode n=x.RootElement.Path(F"Element[Name='{file}']/ID")
if(!n) end "not found"
ID=n.Value
out ID
Posts: 51
Threads: 25
Joined: Oct 2014
Thanks a lot !
Posts: 1,338
Threads: 61
Joined: Jul 2006
For a better understanding how to work with xml
see QM help
Help>Reference
click index tab type in IXml interface
Also search the forum for xml
Posts: 51
Threads: 25
Joined: Oct 2014
Thanks for your reply
I've looked the XML help in QM, but i'm having a problem again :p
For this XML :
<XML>
<Elements nextID="4">
<Element>
<ID>1</ID>
<Date>2015-03-05T14:33:48</Date>
<Name>File1</Name>
<Link>Link1</Link>
</Element>
<Element>
<ID>2</ID>
<Date>2015-03-05T14:33:48</Date>
<Name>File2</Name>
<Link>Link2</Link>
</Element>
<Element>
<ID>3</ID>
<Date>2015-03-05T14:33:48</Date>
<Name>File3</Name>
<Link>Link3</Link>
</Element>
</Elements>
</XML>
The given code does not work anymore, but i'm sure i have to modify something in
IXmlNode n=x.RootElement.Path(F"Element[Name='{file}']/ID")
I tried :
IXmlNode n=x.RootElement.Path(F"[XML][Elements]Element[Name='{file}']/ID")
It work, but i can only get the ID of the File1, if str file="File2", the out ID is still 1
How can i Fix this ? Thanks in advance !
Posts: 1,338
Threads: 61
Joined: Jul 2006
your syntax was not correct
Function
Function4
str XML=
;<XML>
;;<Elements nextID="4">
;;;;<Element>
;;;;;;<ID>1</ID>
;;;;;;<Date>2015-03-05T14:33:48</Date>
;;;;;;<Name>File1</Name>
;;;;;;<Link>Link1</Link>
;;;;</Element>
;;;;<Element>
;;;;;;<ID>2</ID>
;;;;;;<Date>2015-03-05T14:33:48</Date>
;;;;;;<Name>File2</Name>
;;;;;;<Link>Link2</Link>
;;;;</Element>
;;;;<Element>
;;;;;;<ID>3</ID>
;;;;;;<Date>2015-03-05T14:33:48</Date>
;;;;;;<Name>File3</Name>
;;;;;;<Link>Link3</Link>
;;;;</Element>
;;</Elements>
;</XML>
str file="File1"
str ID
IXml x._create
x.FromString(XML)
IXmlNode n=x.RootElement.Path(F"Elements/Element[Name='{file}']/ID")
if(!n) end "not found"
ID=n.Value
out ID
file="File2"
n=x.RootElement.Path(F"Elements/Element[Name='{file}']/ID")
if(!n) end "not found"
ID=n.Value
out ID
Posts: 51
Threads: 25
Joined: Oct 2014
Oh ok thanks ! I'm learning more everyday