I am trying to get a particular field that only occurs once inside a xml file which always has the same format, which should have been a simple task.
The field I want is "MaterialDefinitionID", I've used firefox firebug to copy the xpath which worked for all the other documents I've done except this one. At first I thought the XPATH was something complicated that firebug didn't get right but it appears to be valid to me.
The XPATH I am using is: /CPS/DA/ScghP/lkm123/ReqSqe/MATreq/MaterialDefinitionID
The xml file I am trying to get the data from:
<?xml version="1.0" encoding="UTF-8"?>
<CPS xmlns="http://www.wonderware.com/wwei/v0201/schemas" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<AA/>
<DA>
<ScghP>
<ID>1741284-WOG</ID>
<Location/>
<PublishedDate>2014-03-05 16:03:36</PublishedDate>
<StartTime>1/28/2014 12:00:00 AM</StartTime>
<EndTime>1/28/2014 1:27:44 AM</EndTime>
<lkm123>
<ID>54123s0</ID>
<OLKM>54123s0 (EPIC Bar)</OLKM>
<StartTime>1/28/2014 12:00:00 AM</StartTime>
<EndTime>1/28/2014 1:27:44 AM</EndTime>
<Priority>0</Priority>
<ReqSqe>
<ID>000xxxx</ID>
<Description>epic item</Description>
<EarliestStartTime>1/28/2014 12:00:00 AM</EarliestStartTime>
<LatestEndTime>1/28/2014 1:27:44 AM</LatestEndTime>
<Duration>0H00M00SPT0</Duration>
<MArked/>
<MATreq>
<MaterialDefinitionID>54123s0</MaterialDefinitionID>
<Description>EPIC Bar</Description>
<Location/>
<Quantity/>
<MPRPAZ/>
<MPRPAZ/>
<LKPK>Required</LKPK>
</MATreq>
<ReqSqe/>
<LKPK>Required</LKPK>
</ReqSqe>
</lkm123>
<Any/>
</ScghP>
</DA>
</CPS>
The document has been refactored to protect the client's data but the structure for the relevant
components has been preserved.
Thank you for your time and any help offered.
EDIT: So I am trying to define a namespace and fetch the MaterialDefinitionID field using XSLT, the script I have so far is:
<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ww="wonderware.com/wwei/v0201/schemas">
<xsl:template match="/">
<xsl:for-each select="ww:CPS/ww:DA/ww:ScghP/ww:lkm123/ww:ReqSqe/ww:MATreq">
MaterialDefinitionID: <xsl:apply-templates select="ww:MaterialDefinitionID"/>;
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Something exactly like this worked for other files that didn't have the namespace issue, but not
here for some reason.