xml - Not able to get value of data if it has <b> or <i> in Word Template using VBA -
i able read xml file , convert in array successfully. want add formatting in data. reason have added , tag in xml not able value of tag if has or or other formatting tag.
here code:
<?xml version="1.0" encoding="utf-8"?> <testclass> <testobject> <site><b><i>whatsapp</i></b></site> <url>https://www.whatsapp.com/abc/</url> </testobject> <testobject> <site>facebook</site> <url>https://www.facebook.com/xyz/</url> </testobject> <testobject> <site>twitter</site> <url>https://www.twitter.com/abc/</url> </testobject> </testclass> code:
dim oxmlfile object dim xmlfilename string dim sites object dim urls object set oxmlfile = createobject("microsoft.xmldom") xmlfilename = "c:\users\abc\desktop\files\test.xml" oxmlfile.load (xmlfilename) set sites = oxmlfile.selectnodes("testclass/testobject/site/text()") set urls = oxmlfile.selectnodes("testclass/testobject/url/text()") //sites `facebook` , `twitter` if remove <b> , <i>, work fine , value of 3 elements.
please suggest how manage formatting while getting value xml.
its not allowed use < or > inside xml-textblock. have "mask" them. best convert < < , > >
have @ this: https://en.wikipedia.org/wiki/list_of_xml_and_html_character_entity_references
background of problem:
the xml parser read whole structure of file. every tag (words enclosed in < , >) create new node inside internal tzree. if want access node going down tree.
in example: if want testclass/testobject/site/text() parser first create tree this:
testclass +--testobject | +--site | |+--b | | +--i | | +--text=whatsapp | +--url | +--text=https://www.whatsapp.com/abc/ +--testobject | +--site | | +--text=facebook | +--url | +--text=https://www.facebook.com/xyz/ then follows xpath testclass/testobject/site/ , take node
+--site | +--b | +--i | +--text=whatsapp this node have no text. retuns empty string
Comments
Post a Comment