Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21096

Problem with adding XML-Node

$
0
0
Hi,

i need to add a Node at a specific place in an XML document.

At the Moment i m using .appendChild. Is there another function beside .insertBefore to add a node after a specific Node.
The Problem is that the Node after this one isnt always the same.

Another Problem I have is that i get the following output using .appendChild.

<DataSet xmlns=""/></LN0>

The attribute xmlns shouldnt be there and </LN0> should be in the next line with one tabstop less.

The Code I m using is the following:

Code:

Public Sub xXMLW (Manufacturer As String,FilePath As String) '-->DATASet

        'On Error GoTo ErrorHandler

        Dim xDoc As MSXML2.DOMDocument
        Dim GooseNode As MSXML2.IXMLDOMElement
        Dim DataSet As MSXML2.IXMLDOMElement


        Set xDoc = New MSXML2.DOMDocument

        '-->Prooves whether the document is a valid XML Document.
        xDoc.validateOnParse = True

        '-->DTD = Document Type Definition

        If xDoc.load(FilePath) = False Then

                MsgBox ("Unable to load File.",vbExclamation,OCC)
        Else

                If Manufacturer = "SIEMENS" Then

                        Set GooseNode = xDoc.selectSingleNode("//LDevice[@inst = 'Ln1']/LN0")

                        Set DataSet = CreateNode(xDoc,GooseNode,"DataSet")
                        'CreateAttribute(GooseNode,"name","Dataset")



                ElseIf Manufacturer = "ABB" Then



                End If
                xDoc.Save(FilePath)
                MsgBox("GOOSE succesfully written to: " & vbNewLine & Right(FilePath, Len(FilePath) - InStrRev(FilePath, "\")),vbInformation,OCC)
        End If

        Set GooseNode = Nothing
        Set xDoc = Nothing

        'ErrorHandler:
        '        Resume Next
End Sub

Private Function CreateNode(xDoc As DOMDocument, ParentNode As IXMLDOMNode, NodeName As String) As MSXML2.IXMLDOMElement

Dim Node As MSXML2.IXMLDOMElement
Dim cNode As MSXML2.IXMLDOMElement

    'Create the node
    Set Node = xDoc.createElement(NodeName)

    'Add the node to the document

        ParentNode.appendChild(Node)



    Set CreateNode = Node

    Set objNode = Nothing
End Function

best regards

Sascha

EDIT:

I managed to add the Node at the right position.

But now i ve got 2 Problems:

The resulting xml should look like this

Code:

<LDevice desc="Ln1" inst="Ln1">
              <Private type="Siemens-MasterId">a150f69d-4a9e-4bda-b00c-8a7c58fbd963</Private>
              <LN0 desc="General" lnClass="LLN0" lnType="SIPROTEC5_LNType_LLN0_LDevice_Generic" inst="">
                  <Private type="Siemens-MasterId">9911d398-7f8c-4663-a467-b55cf3e073ca</Private>
                  <DataSet name="Dataset">
                    <FCDA ldInst="Ln1" lnClass="LLN0" fc="ST" daName="stVal" doName="Mod" prefix=""/>
                    <FCDA ldInst="Ln1" lnClass="LLN0" fc="ST" daName="q" doName="Mod" prefix=""/>
                    <FCDA ldInst="Ln1" lnClass="LLN0" fc="ST" daName="stVal" doName="Beh" prefix=""/>
                    <FCDA ldInst="Ln1" lnClass="LLN0" fc="ST" daName="q" doName="Beh" prefix=""/>
                    <FCDA ldInst="Ln1" lnClass="ZLIN" lnInst="1" fc="ST" daName="stVal" doName="Mod" prefix=""/>
                    <FCDA ldInst="Ln1" lnClass="ZLIN" lnInst="1" fc="ST" daName="q" doName="Mod" prefix=""/>
                    <FCDA ldInst="Mod3_FN1_ComChannel" lnClass="LCCH" lnInst="2" fc="ST" daName="stVal" doName="ChLiv" prefix=""/>
                    <FCDA ldInst="Mod3_FN1_ComChannel" lnClass="LCCH" lnInst="2" fc="ST" daName="q" doName="ChLiv" prefix=""/>
                    <FCDA ldInst="Ln1_5051NOCgndA1" lnClass="PTOC" prefix="ND_" lnInst="2" fc="ST" daName="stVal" doName="ActDynSet"/>
                    <FCDA ldInst="Ln1_5051NOCgndA1" lnClass="PTOC" prefix="ND_" lnInst="2" fc="ST" daName="q" doName="ActDynSet"/>
                    <FCDA ldInst="Ln1_5051NOCgndA1" lnClass="PTOC" prefix="ND_" lnInst="2" fc="ST" daName="stVal" doName="Health"/>
                    <FCDA ldInst="Ln1_5051NOCgndA1" lnClass="PTOC" prefix="ND_" lnInst="2" fc="ST" daName="q" doName="Health"/>
                    <FCDA ldInst="Ln1_5051NOCgndA1" lnClass="PTOC" prefix="ND_" lnInst="2" fc="ST" daName="stVal" doName="Inactive"/>
                    <FCDA ldInst="Ln1_5051NOCgndA1" lnClass="PTOC" prefix="ND_" lnInst="2" fc="ST" daName="q" doName="Inactive"/>
                    <FCDA ldInst="Ln1_5051OC1pole1" lnClass="PTRC" lnInst="1" fc="ST" daName="general" doName="Str" prefix=""/>
                    <FCDA ldInst="Ln1_5051OC1pole1" lnClass="PTRC" lnInst="1" fc="ST" daName="q" doName="Str" prefix=""/>
                    <FCDA ldInst="Ln1_8521PermOverr" lnClass="PSCH" prefix="POTT_" lnInst="1" fc="ST" daName="stVal" doName="EchoWei"/>
                    <FCDA ldInst="Ln1_8521PermOverr" lnClass="PSCH" prefix="POTT_" lnInst="1" fc="ST" daName="q" doName="EchoWei"/>
                  </DataSet>
                  <DOI name="Mod" desc="Mode (controllable)">

I need to insert the DataSet with all the ChildNodes. My result looks like this:

Code:

<DataSet xmlns="" name="Dataset"/><DOI name="Mod" desc="Mode (controllable)">
How do i get rid of the attribute xmlns and how do i get the right form. I mean <DataSet name=""></DataSet> and <DOI> in a new line instead of <DataSet xmlns="" name="Dataset"/><DOI>

Thanks in advance.

Sascha

Viewing all articles
Browse latest Browse all 21096

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>