NeilA Posted April 7, 2009 Report Share Posted April 7, 2009 I have gotten used to the awkwardness of XML in LabVIEW but have just come up against a massive problem of using XPath and trying to parse namespaced xml. Basically where XPath used to do the trick it now doesnt because parts of my xml are in a different namespaces. I cant figure out how to get acces to the namespace manager or anything (which is what you need to do according to google). I need to talk to my colleague who has just added the namespaces and made my day very hard, but, I may just remove them for my simple implementation if there is no way round it in LabVIEW. I have attached an example XML where I used to be able to loadXML String and then SelectSingleNode with an XPath of /soap:Envelope/soap:Header/UUID/UUID to get the guid. Any ideas on what to use? I have had a look round in the constructors but cant work out how to do this, is it me or does this just seem like even more hard work, blooming XML :headbang: Many Thanks in advance.. <?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Header> <UUID xmlns="http://RMS/"> <UUID>guid</UUID> </UUID> </soap:Header> <soap:Body> <ControlResume xmlns="http://RMS/"> <ParameterList> <Parameter> <Type>string</Type> <Name>string</Name> <Value> <string>string</string> <string>string</string> </Value> <Units>string</Units> </Parameter> <Parameter> <Type>string</Type> <Name>string</Name> <Value> <string>string</string> <string>string</string> </Value> <Units>string</Units> </Parameter> </ParameterList> </ControlResume> </soap:Body> </soap:Envelope> Quote Link to comment
mje Posted April 7, 2009 Report Share Posted April 7, 2009 QUOTE (NeilA @ Apr 6 2009, 02:14 PM) I have attached an example XML where I used to be able to loadXML String and then SelectSingleNode with an XPath of /soap:Envelope/soap:Header/UUID/UUID to get the guid.... <UUID xmlns="http://RMS/"> That path isn't correct, your XML puts the parent UUID element within the http://RMS/ namespace. Quote Link to comment
NeilA Posted April 7, 2009 Author Report Share Posted April 7, 2009 QUOTE (MJE @ Apr 6 2009, 07:24 PM) That path isn't correct, your XML puts the parent UUID element within the http://RMS/ namespace. Sorry to be an idiot but could you please explain further? I have tried using different namespaces and xpath combinations but cant get any further, are you suggesting that I still use SelectSingleNode method of the xpath class but with a different xpath!?! Thanks Quote Link to comment
Matthew Zaleski Posted April 7, 2009 Report Share Posted April 7, 2009 QUOTE (NeilA @ Apr 6 2009, 03:43 PM) Sorry to be an idiot but could you please explain further? I have tried using different namespaces and xpath combinations but cant get any further, are you suggesting that I still use SelectSingleNode method of the xpath class but with a different xpath!?!Thanks Welcome to the world of XML. What MJE is telling you is that you did a deliberate override of the namespace for the UUID element (you gave it the namespace "http://RMS/"). Therefore /soap:Envelope/soap:Header/UUID/UUID will fail at the first UUID element since it isn't in the default namespace within the XML. I'm not familiar with the namespace "http://RMS/". Did you make that up? If so, modify your XML header: <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:rms="http://RMS/"> and add that rms: prefix to your UUID element in XML file. Then the following XPath will be valid: /soap:Envelope/soap:Header/rms:UUID Quote Link to comment
NeilA Posted April 8, 2009 Author Report Share Posted April 8, 2009 QUOTE (Matthew Zaleski @ Apr 6 2009, 09:23 PM) Welcome to the world of XML. Yeah Thanks, I have been happily using XPath without any issues but the addition of namespaces has seemed to just add headaches. I dont have control of the namespaces this XML is the soap message sent to me from another system. I have been playing around with the LabVIEW XML parser property and invoke nodes as they contain a function to ignore the namespaces but the LabVIEW implementation is based around DOM and I find it really cumbersome after XPath plus I dont really want to re-write everything. Is there any way I can access the namespaces myself (ie namespace manager/nametable (bear in mind I got this info from the net I have only just heard about them and I dont know if I am asking the correct thing lol!))to recover the XPath solutions I have already implemented. Thanks for the help so far. Neil. Sorry, Not to worry chatted to my colleague doing my other system. I am pretty certain that I will always be using the RMS namespace etc. So to make it easier I have the incoming message pass through a vi that removes all the namespace stuff and makes it work again in XPath. Thanks for all your help though. Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.