Question
· Feb 14, 2020

%XML.Reader

Hi guys,

I need help because I have no idea how to proceed further and documentation does not explaining this solution.

I have XML like this:

<?xml version="1.0"?>

<ProductionPackage xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" JobName="10006_8046_L69">

  <Barcode>1200002101</Barcode>

  <DueDate>31.12.5000 23:59:59</DueDate>

  <BasicMaterial>1.0038</BasicMaterial>

  <RawMaterial>St37-120</RawMaterial>

  <RawMaterialThicknessUnit>mm</RawMaterialThicknessUnit>

  <JobNote />

  <CreatedBy>stko</CreatedBy>

  <ChangedBy>stko</ChangedBy>

  <Workplace WorkplaceName="TruLaser 3030 (L49)">

    <Barcode>0800000029</Barcode>

    <CostCenter />

    <Activity>2D-Tafelbearbeitung</Activity>

    <MachineName>L49</MachineName>

    <MachineType>51</MachineType>

    <ControlName>Sin 840D</ControlName>

    <ControlType>1</ControlType>

    <ProcessingAreaX>3000.00</ProcessingAreaX>

    <ProcessingAreaY>1500.00</ProcessingAreaY>

    <ProcessingAreaZ>115.00</ProcessingAreaZ>

  </Workplace>

 

Im trying to read all nodes within %XML.Reader and Correlate. For parents it's not problem and I can get it. But I have no idea what to do if I want get Workplace with all his childs.

 Class dhr.production.article.xml.productionPackage Extends (%Persistent, %XML.Adaptor)
{ 
  Parameter XMLNAME = "ProductionPackage"; 
  Property Barcode As %Integer; Property DueDate As %String; 
  Property BasicMaterial As %Float; 
  Property RawMaterial As %String; 
  Property Workplace As dhr.production.article.xml.workplace; 
}
Class dhr.production.article.xml.workplace Extends (%Persistent, %XML.Adaptor)
{ 
 Parameter XMLNAME = "Workplace"; 
 Property Barcode As %Integer; 
 Property MachineName As %String; 
 Property MachineType As %String; 
 Property ControlName As %String; 
 Property ControlType As %Integer;
}

For writing values from parrent it working fine, but in documentation there is no mention how I can get output from childrens and siblings. I tried object.Workplace.Barcode but does not work at all.

 ClassMethod getFiles(pDir As %String, pFileSpec As %String)
{
    SET tRS = ##class(%ResultSet).%New("%Library.File:FileSet"),
        tSC = tRS.Execute(pDir,pFileSpec)     

    WHILE tRS.Next() 
    {
        SET filePath = tRS.Get("Name"),
            lastModified = tRS.Get("DateModified"),
            fileType = tRS.Get("Type")
                
        SET xmlReader = ##class(%XML.Reader).%New(),
            xmlStatus = xmlReader.OpenFile(filePath)
            
        DO xmlReader.Correlate("ProductionPackage", "dhr.production.article.xml.productionPackage")
        
        DO xmlReader.Next(.object, .xmlStatus)
        
        WRITE !,object.Barcode     
  }
                  
       
    QUIT
}
Discussion (9)1
Log in or sign up to continue

I have generated classes now by using XML Schema, but still not working 

 Class TruLaser.ProductionPackage Extends (%Persistent, %XML.Adaptor) [ ProcedureBlock ]
{ 
Parameter XMLNAME = "ProductionPackage"; 
Parameter XMLSEQUENCE = 1; 
Property Barcode As %xsd.int(XMLNAME = "Barcode") [ Required ]; 
Property DueDate As %String(MAXLEN = "", XMLNAME = "DueDate") [ Required ]; 
Property BasicMaterial As %xsd.float(XMLNAME = "BasicMaterial") [ Required ]; 
Property RawMaterial As %String(MAXLEN = "", XMLNAME = "RawMaterial") [ Required ]; 
Property RawMaterialThicknessUnit As %String(MAXLEN = "", XMLNAME = "RawMaterialThicknessUnit") [ Required ]; 
Property JobNote As %String(MAXLEN = "", XMLNAME = "JobNote") [ Required ]; 
Property CreatedBy As %String(MAXLEN = "", XMLNAME = "CreatedBy") [ Required ]; 
Property ChangedBy As %String(MAXLEN = "", XMLNAME = "ChangedBy") [ Required ]; 
Property Workplace As TruLaser.Workplace(XMLNAME = "Workplace") [ Required ]; 
Property ManufacturingOrders As TruLaser.TcBoManufacturingOrder(XMLNAME = "ManufacturingOrders", XMLPROJECTION = "WRAPPED") [ Required ]; Relationship ProductionOrders As TruLaser.ProductionOrder(XMLITEMNAME = "ProductionOrder", XMLNAME = "ProductionOrders", XMLPROJECTION = "COLLECTION") [ Cardinality = many, Inverse = ProductionPackage ]; 
Relationship Parts As TruLaser.Part(XMLITEMNAME = "Part", XMLNAME = "Parts", XMLPROJECTION = "COLLECTION") [ Cardinality = many, Inverse = ProductionPackage1 ]; 
Property NcPrograms As TruLaser.NcProgram(XMLNAME = "NcPrograms", XMLPROJECTION = "WRAPPED") [ Required ]; 
Property RequiredSheets As TruLaser.Sheet(XMLNAME = "RequiredSheets", XMLPROJECTION = "WRAPPED") [ Required ]; 
Property LaserTechnoTables As TruLaser.LaserTechnoTable(XMLNAME = "LaserTechnoTables", XMLPROJECTION = "WRAPPED") [ Required ]; 
Relationship UsedLaserTechnoTables As TruLaser.UsedLaserTechnoTable(XMLITEMNAME = "UsedLaserTechnoTable", XMLNAME = "UsedLaserTechnoTables", XMLPROJECTION = "COLLECTION") [ Cardinality = many, Inverse = ProductionPackage2 ]; 
Property TotalRuntime As %xsd.float(XMLNAME = "TotalRuntime") [ Required ]; 
Property RawMaterialThickness As %xsd.float(XMLNAME = "RawMaterialThickness") [ Required ]; 
Property TotalPartCount As %xsd.byte(XMLNAME = "TotalPartCount") [ Required ]; 
Property TotalSheetCount As %xsd.byte(XMLNAME = "TotalSheetCount") [ Required ]; Property Waste As %xsd.float(XMLNAME = "Waste") [ Required ]; Property JobName As %String(MAXLEN = "", XMLNAME = "JobName", XMLPROJECTION = "ATTRIBUTE");
Class TruLaser.TcBoManufacturingOrder Extends (%Persistent, %XML.Adaptor) [ ProcedureBlock ]
{
Parameter XMLNAME = "TcBoManufacturingOrder"; 
Parameter XMLSEQUENCE = 1; 
Property Barcode As %xsd.int(XMLNAME = "Barcode") [ Required ]; 
Property ProgramNo As %String(MAXLEN = "", XMLNAME = "ProgramNo") [ Required ]; 
Property NoOfRuns As %xsd.byte(XMLNAME = "NoOfRuns") [ Required ]; Relationship ProductionOrders As TruLaser.Order(XMLITEMNAME = "Order", XMLNAME = "ProductionOrders", XMLPROJECTION = "COLLECTION") [ Cardinality = many, Inverse = TcBoManufacturingOrder ]; 
Property ProcessingTimeTotal As %xsd.float(XMLNAME = "ProcessingTimeTotal") [ Required ]; 
Property ManufacturingOrderNo As %String(MAXLEN = "", XMLNAME = "ManufacturingOrderNo", XMLPROJECTION = "ATTRIBUTE");
}
ERROR #5002: Cache error: <CLASS DOES NOT EXIST>XMLImportElements+96^TruLaser.TcBoManufacturingOrder.1 *TruLaser.Order for element ProductionOrders (ending at line 28 character 25)

Also im still not able access all values for example :  object.LaserTechnoTables.MaxLaserPower