Results 1 to 3 of 3

Thread: edit xml document

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2010
    Posts
    79

    edit xml document

    I have an XML document that I am trying to update specific nodes but the node attributes seem to get in the way. If I leave the attributes, "xmlns:.." and try to search, i get an error that says the node is nothing BUT if I rename the "xmlns:" to "ns", the search works. why is this?? I am trying to use the XMLDocument since once the change has been made, the file has to be moved to another network folder.
    If anyone has a better idea than what I am trying to do, please let me know. The full XML is below as is the code I am trying to use.
    Code:
    <?xml version="1.0" encoding="utf-8" ?>
    <soap:Envelope xmlns:xsd= "http:=//sometext/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
      <soap:Body>
        <fiAPI xmlns="http://sometextr.com" xmlns:ITI="http://www.Wnet.com/" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:xenc="http://www.w3.org/2001/xmlenc#" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://sometext.api.com/API.xsd">
        <fiHeader Version="2.2">
        <Service Name="TST1337" Version="10.0">
        <DateTime>2020-01-09T18:08:02-06:00</DateTime>
        <UUID>23e7a103-fa5b-blah-blah-bf18b1068b4b</UUID>
        </Service>
      <Security>
        <AuthenticationMaterial>
          <SignedToken>
            <EncryptedData>
              <CipherData xmlns="http://www.w3.org/2001/04/xmlenc#">
                <CipherValue>anencryptedstring</CipherValue>
              </CipherData>
            </EncryptedData>
          </SignedToken>
        </AuthenticationMaterial>
        <PrincipalID>Prometheus</PrincipalID>
        <TrustRelationship xmlns="http://www.Wnet.com/">TrustedUser</TrustRelationship>
      </Security>
      <Client>
        <VendorID>FNB-AK!</VendorID>
        <AppID>FNB-AK!INST000</AppID>
        <OrgID>00</OrgID>
        <SessionID></SessionID>
      </Client>
      <DataSource>
        <URI>TEST</URI>
      </DataSource>
    </fiHeader>
    <Request Echo="false" TypeOfRequest="GetName">
      <NameID>5371</NameID>
      <GroupName>TEST</GroupName>
      <InstNumber>00</InstNumber>
      <Sequence>1</Sequence>
      <Type>Names</Type>
      <Type>AccountNameRelationships</Type>
    </Request>
    </fiAPI>
      </soap:Body>
    </soap:Envelope>
    
           Dim MyXML As New XmlDocument()
            MyXML.Load("..\..\FNBAXMLFile.xml")
            Dim MyXMLNode As XmlNode = MyXML.SelectSingleNode("/fiAPI/Security/AuthenticationMaterial/SignedToken/EncryptedData/CipherData/CipherValue")
            If MyXMLNode IsNot Nothing Then
                MyXMLNode.ChildNodes(0).InnerText = "CHANGED"
                MyXML.Save("C:\Temp\XmlTest.xml")
            Else
                MessageBox.Show("node is Nothing")
            End If ' Save the Xml.
    Last edited by ahbenshaut; Mar 25th, 2020 at 07:39 AM.

  2. #2
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,531

    Re: edit xml document

    It doesn't find it because it's in a namespace. That's what the xmlns does... creates an XML NameSpace... it "works" when you change it because you break the rules and you break it out of the namespace. Fortunately you don't need to do that (nor should you) ... what you need to do is add a NamespaceManager to add the xsi namespace - I don't thinks its necessary to add xsd as that's by default, try it without it, if it still fails, then add it too - once you have the namespace(s) added, to the manager and the manager linked to the document, you can search your nodes just like you're trying to do.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Feb 2010
    Posts
    79

    Re: edit xml document

    Quote Originally Posted by techgnome View Post
    It doesn't find it because it's in a namespace. That's what the xmlns does... creates an XML NameSpace... it "works" when you change it because you break the rules and you break it out of the namespace. Fortunately you don't need to do that (nor should you) ... what you need to do is add a NamespaceManager to add the xsi namespace - I don't thinks its necessary to add xsd as that's by default, try it without it, if it still fails, then add it too - once you have the namespace(s) added, to the manager and the manager linked to the document, you can search your nodes just like you're trying to do.

    -tg
    hmmm
    After some moving some code around and with some help, I was able to get it to work by using:
    Code:
            
    Dim MyXML As New XmlDocument()
            MyXML.Load("..\..\FNBAXMLFile.xml")
            txtResponse.Text = MyXML.OuterXml
            Dim node As XmlNodeList = MyXML.GetElementsByTagName("CipherValue")
            If node IsNot Nothing Then
                node(0).InnerText = "ALL RIGHTY THEN"
                MyXML.Save("C:\Temp\XmlTest.xml")
            Else
                MessageBox.Show("node is Nothing")
            End If

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width