1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

流通BMSのShipmentNotification(出荷予定)データを書き込む

Last updated at Posted at 2022-10-17

概要

流通BMSのShipmentNotification(出荷予定)データを書き込む処理をやってみた。
注)このプログラムは大まかな処理部分のみを記述しています。

VB.NET
Private xDocument As XmlDocument
Private root As System.Xml.XmlElement
Private lv2 As XmlNode
Private lv3 As XmlNode
Private lv4 As XmlNode
Private lv5 As XmlNode
Private lv6 As XmlNode
Private lv7 As XmlNode
Private lv8 As XmlNode
Private Attr As System.Xml.XmlAttribute

''' <summary>
''' 出荷予定データをXML形式で出力する
''' </summary>
''' <param name="dt">発注明細データ</param>
''' <param name="path">保存先パス</param>
''' <returns></returns>
''' <remarks></remarks>
Public Function ExportShukkaDataXML(dt As DataTable, path As String) As Boolean

	xDocument = New XmlDocument  'XMLドキュメント作成

	Dim str As String = ""

	str = "<?xml version=""1.0"" encoding=""UTF-8"" ?>"
	str &= "<sh:StandardBusinessDocument xmlns:common=""urn:SecondGenEDI:common:Japan:1"" xmlns:deliver=""urn:SecondGenEDI:deliver:Japan:1"" xmlns:sh=""http://www.unece.org/cefact/namespaces/StandardBusinessDocumentHeader"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xsi:schemaLocation=""urn:SecondGenEDI:common:Japan:1 ../Schemas/SGE_ShipmentNotificationProxy1_3.xsd http://www.unece.org/cefact/namespaces/StandardBusinessDocumentHeader ../Schemas/sbdh/StandardBusinessDocumentHeader.xsd"">"
	str &= "</sh:StandardBusinessDocument>"
	
	'XMLドキュメントを作成
	xDocument.LoadXml(str)

	'root指定
	root = xDocument.DocumentElement
	
	'名前空間の定義
	sh = "http://www.unece.org/cefact/namespaces/StandardBusinessDocumentHeader"
	common = "urn:SecondGenEDI:common:Japan:1"
	deliver = "urn:SecondGenEDI:deliver:Japan:1"
	xsi = "http://www.w3.org/2001/XMLSchema-instance"
	schemaLocation = "urn:SecondGenEDI:common:Japan:1 ../Schemas/SGE_ShipmentNotificationProxy1_3.xsd http://www.unece.org/cefact/namespaces/StandardBusinessDocumentHeader ../Schemas/sbdh/StandardBusinessDocumentHeader.xsd"


	'2階層目にエレメントを追加
	lv2 = xDocument.CreateElement("sh", "StandardBusinessDocumentHeader", sh.NamespaceName)
	root.AppendChild(lv2)
	
	'3階層目にエレメントを追加
	lv3 = xDocument.CreateElement("sh", "HeaderVersion", sh.NamespaceName)
	lv3.InnerText = "1.3"
	lv2.AppendChild(lv3)
	
	'3階層目にエレメントを追加
	lv3 = xDocument.CreateElement("sh", "Sender", sh.NamespaceName)'1---Sender
	lv2.AppendChild(lv3)

	'4階層目に追加する要素(テキスト)を作成
	lv4 = xDocument.CreateElement("sh", "Identifier", sh.NamespaceName)
	lv4.InnerText = "123456" '送信元の取引先コード

	'4階層目に追加する属性(テキスト)を作成
	Attr = xDocument.CreateAttribute("Authority")'2---Sender属性を追加する
	Attr.Value = "CODE"

	'4階層目に属性(テキスト)を追加
	lv4.Attributes.Append(Attr)

	'4階層目にエレメントを追加
	lv3.AppendChild(lv4)

	'その他の項目も同様に作成する
	
	
    Dim dv As DataView

    dv = New DataView(dt)
    Dim dtDen As DataTable = dv.ToTable(True, "伝票番号")
    dv.Dispose()

    '伝票番号分ループする
    For i As Integer = 0 To dtDen.Rows.Count - 1

        '発注データを伝票番号で抽出する
        dv = New DataView(dt)
        dv.RowFilter = "伝票番号 ='" & dtDen.Rows(i).Item("伝票番号") & "'"
        Dim dtMeisai As DataTable = dv.ToTable
        dv.Dispose()

        '明細行分ループする
        For m As Integer = 0 To dtMeisai.Rows.Count - 1
            '伝票明細情報
	        '---lineItem
	        lv5 = xDocument.CreateElement("lineItem")
	        lv4.AppendChild(lv5)

	        '---lineID
	        lv6 = xDocument.CreateElement("lineID")
	        lv5.AppendChild(lv6)

	        '---lineNumber 伝票行番号 
	        lv7 = xDocument.CreateElement("lineNumber")
	        lv7.InnerText = dtMeisai.Rows(m).item("行番号")
	        lv6.AppendChild(lv7)
	        
	        'その他の項目も同様
        Next

    Next
	
	'xmlファイルを保存する
    xDocument.Save(path)

End Function
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?