How to extract information from an XML code?

reinaldo colon
reinaldo colon used Ask the Experts™
on
1.What code can be uses to looks for values in the below XML code example?  For example,  looks for "LaserPower" and then extract the values that follows . In the below code the value that follows is 95.  

2- Can we do that with FactoryTalk or a PLC?

RESULT GETXML
<?xml version="1.0" encoding="UTF-8"?>
<DynaMark-Project title="Demo" version="0.2">
   <OfflineEditorData>
      <MachineSetup type="string" />
      <EditorType type="string" />
      <EditorVersion type="string">0.0.0.0</EditorVersion>
   </OfflineEditorData>
   <Dynamark-Object type="CObjText">
      <CObjBaseData template-version="0.2">
         <ObjName type="string">Text</ObjName>
         <ParamDelaysName type="string">Default</ParamDelaysName>
         <Invers type="bool" value="false" />
         <Mark type="MarkEnableMode" value="true" />
         <Offset type="CPoint" value="-56.0489 16.1231" />
         <ScaleX type="float" value="2" />
         <ScaleY type="float" value="2" />
         <RadiantX type="float" value="-1.5708" />
         <RadiantY type="float" value="-1.5708" />
         <MirrorX type="bool" value="true" />
         <MirrorY type="bool" value="true" />
         <Hatching type="Hatching" value="none" />
         <LaserNr type="integer" value="0" />
         <MinVectorLength type="float" value="0" />
         <XCenterMode type="CenterMode" value="center" />
         <YCenterMode type="CenterMode" value="center" />
         <Locked type="bool" value="false" />
         <EmptyAllowed type="bool" value="true" />
         <ConditionValue type="integer" value="0" />
         <ConditionMask type="integer" value="0" />
         <RegisterConditionMask type="integer" value="0" />
         <RegisterConditionValue type="integer" value="0" />
         <SerialConditionRegister type="integer" value="0" />
         <SerialConditionValue type="integer" value="0" />
      </CObjBaseData>
      <CObjText>
         <Text type="string" />
         <FontName type="string">1LS-Arial</FontName>
         <Spatio type="float" value="0.3" />
         <Proportional type="bool" value="true" />
         <LineCenterMode type="CenterMode" value="center" />
         <CharAngleX type="float" value="0" />
         <CharAngleY type="float" value="0" />
         <Linefeed type="float" value="1.5" />
         <Radius type="float" value="10" />
         <CharRotationMode type="CharRotationMode" value="none" />
         <InverseLineFlow type="bool" value="false" />
         <AlternatingLineFlow type="bool" value="false" />
         <BUIMode type="integer" value="0" />
         <Datasource type="integer" value="1" />
      </CObjText>
   </Dynamark-Object>
   <Dynamark-Object type="CObjText">
      <CObjBaseData template-version="0.2">
         <ObjName type="string">Text 1</ObjName>
         <ParamDelaysName type="string">exp</ParamDelaysName>
         <Invers type="bool" value="false" />
         <Mark type="MarkEnableMode" value="true" />
         <Offset type="CPoint" value="-56.706 8.31374" />
         <ScaleX type="float" value="2" />
         <ScaleY type="float" value="2" />
         <RadiantX type="float" value="-1.5708" />
         <RadiantY type="float" value="-1.5708" />
         <MirrorX type="bool" value="true" />
         <MirrorY type="bool" value="true" />
         <Hatching type="Hatching" value="none" />
         <LaserNr type="integer" value="0" />
         <MinVectorLength type="float" value="0" />
         <XCenterMode type="CenterMode" value="center" />
         <YCenterMode type="CenterMode" value="center" />
         <Locked type="bool" value="false" />
         <EmptyAllowed type="bool" value="true" />
         <ConditionValue type="integer" value="0" />
         <ConditionMask type="integer" value="0" />
         <RegisterConditionMask type="integer" value="0" />
         <RegisterConditionValue type="integer" value="0" />
         <SerialConditionRegister type="integer" value="0" />
         <SerialConditionValue type="integer" value="0" />
      </CObjBaseData>
      <CObjText>
         <Text type="string">LOT A1234567</Text>
         <FontName type="string">1LS-Arial</FontName>
         <Spatio type="float" value="0.3" />
         <Proportional type="bool" value="false" />
         <LineCenterMode type="CenterMode" value="min" />
         <CharAngleX type="float" value="0" />
         <CharAngleY type="float" value="0" />
         <Linefeed type="float" value="1.5" />
         <Radius type="float" value="10" />
         <CharRotationMode type="CharRotationMode" value="none" />
         <InverseLineFlow type="bool" value="false" />
         <AlternatingLineFlow type="bool" value="false" />
         <BUIMode type="integer" value="0" />
         <Datasource type="integer" value="0" />
      </CObjText>
   </Dynamark-Object>
   <Dynamark-Object type="CObjText">
      <CObjBaseData template-version="0.2">
         <ObjName type="string">Text2</ObjName>
         <ParamDelaysName type="string">Default</ParamDelaysName>
         <Invers type="bool" value="false" />
         <Mark type="MarkEnableMode" value="true" />
         <Offset type="CPoint" value="-59.3965 18.7395" />
         <ScaleX type="float" value="7" />
         <ScaleY type="float" value="7" />
         <RadiantX type="float" value="-1.5708" />
         <RadiantY type="float" value="-1.5708" />
         <MirrorX type="bool" value="true" />
         <MirrorY type="bool" value="true" />
         <Hatching type="Hatching" value="none" />
         <LaserNr type="integer" value="0" />
         <MinVectorLength type="float" value="0" />
         <XCenterMode type="CenterMode" value="center" />
         <YCenterMode type="CenterMode" value="center" />
         <Locked type="bool" value="false" />
         <EmptyAllowed type="bool" value="true" />
         <ConditionValue type="integer" value="0" />
         <ConditionMask type="integer" value="0" />
         <RegisterConditionMask type="integer" value="0" />
         <RegisterConditionValue type="integer" value="0" />
         <SerialConditionRegister type="integer" value="0" />
         <SerialConditionValue type="integer" value="0" />
      </CObjBaseData>
      <CObjText>
         <Text type="string" />
         <FontName type="string">1LS-Arial</FontName>
         <Spatio type="float" value="0.3" />
         <Proportional type="bool" value="true" />
         <LineCenterMode type="CenterMode" value="center" />
         <CharAngleX type="float" value="0" />
         <CharAngleY type="float" value="0" />
         <Linefeed type="float" value="1.5" />
         <Radius type="float" value="10" />
         <CharRotationMode type="CharRotationMode" value="none" />
         <InverseLineFlow type="bool" value="false" />
         <AlternatingLineFlow type="bool" value="false" />
         <BUIMode type="integer" value="0" />
         <Datasource type="integer" value="1" />
      </CObjText>
   </Dynamark-Object>
   <Dynamark-Object type="CObjText">
      <CObjBaseData template-version="0.2">
         <ObjName type="string">Text 2</ObjName>
         <ParamDelaysName type="string">exp</ParamDelaysName>
         <Invers type="bool" value="false" />
         <Mark type="MarkEnableMode" value="true" />
         <Offset type="CPoint" value="-52.3633 7.56731" />
         <ScaleX type="float" value="2" />
         <ScaleY type="float" value="2" />
         <RadiantX type="float" value="-1.5708" />
         <RadiantY type="float" value="-1.5708" />
         <MirrorX type="bool" value="true" />
         <MirrorY type="bool" value="true" />
         <Hatching type="Hatching" value="none" />
         <LaserNr type="integer" value="0" />
         <MinVectorLength type="float" value="0" />
         <XCenterMode type="CenterMode" value="center" />
         <YCenterMode type="CenterMode" value="center" />
         <Locked type="bool" value="false" />
         <EmptyAllowed type="bool" value="true" />
         <ConditionValue type="integer" value="0" />
         <ConditionMask type="integer" value="0" />
         <RegisterConditionMask type="integer" value="0" />
         <RegisterConditionValue type="integer" value="0" />
         <SerialConditionRegister type="integer" value="0" />
         <SerialConditionValue type="integer" value="0" />
      </CObjBaseData>
      <CObjText>
         <Text type="string">EXP JAN17 2019</Text>
         <FontName type="string">1LS-Arial</FontName>
         <Spatio type="float" value="0.3" />
         <Proportional type="bool" value="false" />
         <LineCenterMode type="CenterMode" value="min" />
         <CharAngleX type="float" value="0" />
         <CharAngleY type="float" value="0" />
         <Linefeed type="float" value="1.5" />
         <Radius type="float" value="10" />
         <CharRotationMode type="CharRotationMode" value="none" />
         <InverseLineFlow type="bool" value="false" />
         <AlternatingLineFlow type="bool" value="false" />
         <BUIMode type="integer" value="0" />
         <Datasource type="integer" value="0" />
      </CObjText>
   </Dynamark-Object>
   <Dynamark-Object type="CObjBarcode">
      <CObjBaseData template-version="0.2">
         <ObjName type="string">MRC 1</ObjName>
         <ParamDelaysName type="string">Default</ParamDelaysName>
         <Invers type="bool" value="false" />
         <Mark type="MarkEnableMode" value="true" />
         <Offset type="CPoint" value="-54.238 24.9741" />
         <ScaleX type="float" value="8" />
         <ScaleY type="float" value="8" />
         <RadiantX type="float" value="0" />
         <RadiantY type="float" value="0" />
         <MirrorX type="bool" value="true" />
         <MirrorY type="bool" value="true" />
         <Hatching type="Hatching" value="none" />
         <LaserNr type="integer" value="0" />
         <MinVectorLength type="float" value="0" />
         <XCenterMode type="CenterMode" value="center" />
         <YCenterMode type="CenterMode" value="center" />
         <Locked type="bool" value="false" />
         <EmptyAllowed type="bool" value="true" />
         <ConditionValue type="integer" value="0" />
         <ConditionMask type="integer" value="0" />
         <RegisterConditionMask type="integer" value="0" />
         <RegisterConditionValue type="integer" value="0" />
         <SerialConditionRegister type="integer" value="0" />
         <SerialConditionValue type="integer" value="0" />
      </CObjBaseData>
      <CObjBarcode>
         <Text type="string">\\F01123456789012341719011710A1234567</Text>
         <Code type="integer" value="52" />
         <DPI type="integer" value="200" />
         <QuietZoneX type="float" value="2" />
         <QuietZoneY type="float" value="2" />
         <ShortBarLength type="float" value="0.9" />
         <SecurityLevel type="integer" value="0" />
         <StartMode type="integer" value="0" />
         <MarkingMode type="integer" value="1" />
         <QuietzoneMarkingMode type="integer" value="0" />
         <DiameterPerc type="integer" value="80" />
         <Secants type="integer" value="3" />
         <RenderingAutomaticOrder type="bool" value="true" />
         <RenderingStartPosition type="integer" value="0" />
         <HorizontalFlow type="bool" value="false" />
         <AlternatingFlow type="bool" value="true" />
         <SeparateLines type="bool" value="false" />
         <BUIMode type="integer" value="0" />
         <Datasource type="integer" value="0" />
         <CheckDigit type="integer" value="1" />
         <DMSize type="integer" value="0" />
         <DMFormat type="integer" value="0" />
         <DMEnforceBinary type="bool" value="false" />
         <CompositeCode type="integer" value="0" />
         <BarcodePart type="integer" value="0" />
         <QRMask type="integer" value="1" />
         <QRECLevel type="integer" value="0" />
         <QRVersion type="integer" value="0" />
         <QRFormat type="integer" value="0" />
         <QRCompaction type="integer" value="0" />
         <MQRVersion type="integer" value="0" />
         <MQRMask type="integer" value="1" />
         <QRAI type="string" />
         <PDF417ECLevel type="integer" value="0" />
         <PDF417Rows type="integer" value="-1" />
         <PDF417Cols type="integer" value="-1" />
         <PDF417RowColRatio type="string" />
         <CBFFormat type="integer" value="0" />
         <CBFRows type="integer" value="-1" />
         <CBFCols type="integer" value="-1" />
         <MaxiMode type="integer" value="2" />
         <MaxiUndercut type="integer" value="-1" />
         <MaxiPreambleEnabled type="bool" value="false" />
         <MaxiPreambleDate type="string" />
         <MaxiServiceClass type="string" />
         <MaxiCountryCode type="string" />
         <MaxiPostalCode type="string" />
         <DotCodeSizeMode type="integer" value="0" />
         <DotCodeSizeModeParam type="string" />
         <DotCodeFormat type="integer" value="0" />
         <DotCodeFormatParam type="string" />
         <DotCodeMask type="integer" value="0" />
         <DotCodeEncoding type="integer" value="0" />
         <DotCodeDirection type="integer" value="0" />
         <HanXinEnforceBinary type="bool" value="false" />
         <HanXinVersion type="integer" value="0" />
         <HanXinMask type="integer" value="0" />
         <HanXinECLevel type="integer" value="0" />
         <AztecFormat type="integer" value="0" />
         <AztecFormatParameter type="string" />
         <AztecSize type="integer" value="0" />
         <AztecRuneMode type="bool" value="false" />
         <AztecErrorCorrection type="integer" value="0" />
         <AztecEnforceBinary type="bool" value="false" />
         <RatioMode type="integer" value="0" />
         <ModuleSize type="float" value="0.2" />
         <ReturnJumpDelayScale type="float" value="1" />
      </CObjBarcode>
   </Dynamark-Object>
   <Dynamark-Object type="CObjText">
      <CObjBaseData template-version="0.2">
         <ObjName type="string">Text 3</ObjName>
         <ParamDelaysName type="string">exp</ParamDelaysName>
         <Invers type="bool" value="false" />
         <Mark type="MarkEnableMode" value="true" />
         <Offset type="CPoint" value="-46.6441 12.6794" />
         <ScaleX type="float" value="2" />
         <ScaleY type="float" value="2" />
         <RadiantX type="float" value="-1.5708" />
         <RadiantY type="float" value="-1.5708" />
         <MirrorX type="bool" value="true" />
         <MirrorY type="bool" value="true" />
         <Hatching type="Hatching" value="none" />
         <LaserNr type="integer" value="0" />
         <MinVectorLength type="float" value="0" />
         <XCenterMode type="CenterMode" value="center" />
         <YCenterMode type="CenterMode" value="center" />
         <Locked type="bool" value="false" />
         <EmptyAllowed type="bool" value="true" />
         <ConditionValue type="integer" value="0" />
         <ConditionMask type="integer" value="0" />
         <RegisterConditionMask type="integer" value="0" />
         <RegisterConditionValue type="integer" value="0" />
         <SerialConditionRegister type="integer" value="0" />
         <SerialConditionValue type="integer" value="0" />
      </CObjBaseData>
      <CObjText>
         <Text type="string">GTIN 12345678901234</Text>
         <FontName type="string">1LS-Arial</FontName>
         <Spatio type="float" value="0.3" />
         <Proportional type="bool" value="false" />
         <LineCenterMode type="CenterMode" value="min" />
         <CharAngleX type="float" value="0" />
         <CharAngleY type="float" value="0" />
         <Linefeed type="float" value="1.5" />
         <Radius type="float" value="10" />
         <CharRotationMode type="CharRotationMode" value="none" />
         <InverseLineFlow type="bool" value="false" />
         <AlternatingLineFlow type="bool" value="false" />
         <BUIMode type="integer" value="0" />
         <Datasource type="integer" value="0" />
      </CObjText>
   </Dynamark-Object>
   <Parameter-Set>
      <CParamDelays>
         <Name type="string">Default</Name>
         <LaserType type="string">CO2Generic</LaserType>
         <StepPeriod type="integer" value="30" />
         <JumpDelay type="integer" value="100" />
         <MarkDelay type="integer" value="100" />
         <PolygonDelay type="integer" value="20" />
         <LaserOnDelay type="integer" value="70" />
         <LaserOffDelay type="integer" value="110" />
         <T1 type="integer" value="94" />
         <MaxVectorLength type="float" value="0.25" />
         <JumpSpeed type="integer" value="7000" />
         <MarkSpeed type="integer" value="5000" />
         <LaserPower type="float" value="95" />
      </CParamDelays>
   </Parameter-Set>
   <Parameter-Set>
      <CParamDelays>
         <Name type="string">exp</Name>
         <LaserType type="string">CO2Generic</LaserType>
         <StepPeriod type="integer" value="30" />
         <JumpDelay type="integer" value="100" />
         <MarkDelay type="integer" value="100" />
         <PolygonDelay type="integer" value="20" />
         <LaserOnDelay type="integer" value="70" />
         <LaserOffDelay type="integer" value="110" />
         <T1 type="integer" value="94" />
         <MaxVectorLength type="float" value="0.25" />
         <JumpSpeed type="integer" value="7000" />
         <MarkSpeed type="integer" value="5000" />
         <LaserPower type="float" value="95" />
      </CParamDelays>
   </Parameter-Set>
   <Parameter-Set>
      <CParamDelays>
         <Name type="string">lot</Name>
         <LaserType type="string">CO2Generic</LaserType>
         <StepPeriod type="integer" value="30" />
         <JumpDelay type="integer" value="100" />
         <MarkDelay type="integer" value="100" />
         <PolygonDelay type="integer" value="20" />
         <LaserOnDelay type="integer" value="70" />
         <LaserOffDelay type="integer" value="110" />
         <T1 type="integer" value="94" />
         <MaxVectorLength type="float" value="0.25" />
         <JumpSpeed type="integer" value="7000" />
         <MarkSpeed type="integer" value="5000" />
         <LaserPower type="float" value="95" />
      </CParamDelays>
   </Parameter-Set>
</DynaMark-Project>

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2014

Commented:
The XPath should be very close to this:
//LaserPower/@value

Open in new window

Author

Commented:
Who to parse the xml?
Top Expert 2014

Commented:
I haven't used either of the software applications/utilities you mentioned.
Bill PrewTest your restores, not your backups...
Top Expert 2016

Commented:
If you have any comfort with Powershell, then a simple two lines would get the results:

$xml = [xml](Get-Content test.xml)
$xml.'DynaMark-Project'.'Parameter-Set'.CParamDelays.LaserPower | Select-Object Value

Open in new window

value
-----
95   
95   
95

Open in new window



»bp
Bill PrewTest your restores, not your backups...
Top Expert 2016

Commented:
@reinaldo colon,

Are you all set with this now, or do you need more help?  If all set, could you please close it out now.  If you need help with the question close process take a look at:



»bp

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial