Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Select and copy parts of a string
#1
Hello !

I have a string named XML that contains :

Code:
Copy      Help
<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 !
#2
Macro Macro2519
Code:
Copy      Help
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
#3
Thanks a lot ! Smile
#4
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
#5
Thanks for your reply Smile

I've looked the XML help in QM, but i'm having a problem again :p

For this XML :

Code:
Copy      Help
<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

Code:
Copy      Help
IXmlNode n=x.RootElement.Path(F"Element[Name='{file}']/ID")

I tried :
Code:
Copy      Help
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 !
#6
your syntax was not correct
Function Function4
Code:
Copy      Help
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
#7
Oh ok thanks ! I'm learning more everyday Smile


Forum Jump:


Users browsing this thread: 2 Guest(s)