Welcome to the SRP Forum! Please refer to the SRP Forum FAQ post if you have any questions regarding how the forum works.
SRP_Extract_XML
Wondering what the Xpath is supposed to be.
if the command is
Records = Srp_Extract_XML(XML, XPath)
the variable XML contains the data of the XML file
the variable XPath contains the tags in the format "/vendorPlacementData/vendorPlacementDataList/vendorPlacementDataRecord'"
I was comparing to a program I wrote several years ago.
if the command is
Records = Srp_Extract_XML(XML, XPath)
the variable XML contains the data of the XML file
the variable XPath contains the tags in the format "/vendorPlacementData/vendorPlacementDataList/vendorPlacementDataRecord'"
I was comparing to a program I wrote several years ago.
Comments
Below the beginning of the XML data
looking at the data I was thinking that the XPath should have been "vendorPlacementData/vendorPlacementDataList/vendorPlacementDataRecord"
The main node is "vendorPlacementData"
The child node is "vendorPlacementDataList" (Bookstore at W3school)
The next child node is "vendorPlacementDataRecord" (Book at W3school)
Am I missing something?
Can I remove all the data prior to the first proper tag / node vendorPlacementData?
Path = "/x:vendorPlacementData/x:vendorPlacementDataList/x:vendorPlacementDataRecord" Ans = SRP_Extract_Xml(XML, Path, 'xmlns:x="http://"')
I added the namespace as you suggested but got the same result.
Command works with the correct XPath.
Can I get an explanation of the "/x:" in the XPath
So, let's say we have the following XML:
<books xmlns="http://"> <book> <title>Title</title> <author>Author Name</author> <price>5.50</price> </book> </books>
So, books and everything inside of it is in the default namespace, which is normally null. In this case, the default namespace has been renamed to "http://". In order to use SRP_Extract_XML, we have to assign that namespace to a prefix of our choosing. We can use whatever we want. So, I used 'x' when I added that namespace parameter:
SRP_Extract_Xml(XML, Path, 'xmlns:x="http://"')
See "xmlns" followed by a colon and an 'x'? Everything after the colon is our chosen prefix. We could have used 'd' for default. Some XML files have a whole bunch of name spaces, and SRP_Extract_XML allows us to provide custom prefixes for all of them. The caveat, for XPath, is that we have to use those prefixes we invented inside the XPath query. If I use the following XPath:
"/books/book/title"
I get nothing because XPath can't find them. Why? Because this XPath query is telling SRP_Extract_XML to look in the null namespace for books, then in the null namespace for book, then in the null namespace for title. But there is no null namespace in the XML document. There is a default namespace, but it has been named "http://", not null. So, we use this instead:
"/x:books/x:book/x:title"
This query says look in the "http://" namespace for books, then in the "http://" namespace for book, then in the "http://" namespace for title.