Change NameSpace Value on Selected Node

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Rick

    Change NameSpace Value on Selected Node

    I have an XML document that is generated from Infopath, I need to change
    the value of a namespace that is defined in a node in the form:
    <xsf:xDocumentC lass "xmlns:my=value here">.
    when i navigate to the namespace value it is read only and cannot be
    changed. Can anyone tell me how to change this value?

    My Code:

    Dim sSingleNode As XmlNode = objDoc.SelectSi ngleNode("//xsf:Node",
    NamespaceManage r)
    Dim nav As XPathNavigator
    Dim docNav As XPathDocument
    docNav = New XPathDocument(s File)
    nav = docNav.CreateNa vigator
    nav.MoveToRoot( )
    nav.MoveToFirst Child()
    nav.MoveToNext( )
    nav.MoveToFirst Namespace()
    Do
    If nav.Name.ToUppe r = "MY" Then
    nav.Value = Value 'Change value here
    End If
    Loop While nav.MoveToNextN amespace

    Thanks in Advance,
    Rick


  • Martin Honnen

    #2
    Re: Change NameSpace Value on Selected Node



    Rick wrote:
    [color=blue]
    > I have an XML document that is generated from Infopath, I need to change
    > the value of a namespace that is defined in a node in the form:
    > <xsf:xDocumentC lass "xmlns:my=value here">.
    > when i navigate to the namespace value it is read only and cannot be
    > changed. Can anyone tell me how to change this value?
    >
    > My Code:
    >
    > Dim sSingleNode As XmlNode = objDoc.SelectSi ngleNode("//xsf:Node",
    > NamespaceManage r)
    > Dim nav As XPathNavigator
    > Dim docNav As XPathDocument
    > docNav = New XPathDocument(s File)
    > nav = docNav.CreateNa vigator
    > nav.MoveToRoot( )
    > nav.MoveToFirst Child()
    > nav.MoveToNext( )
    > nav.MoveToFirst Namespace()
    > Do
    > If nav.Name.ToUppe r = "MY" Then
    > nav.Value = Value 'Change value here
    > End If
    > Loop While nav.MoveToNextN amespace[/color]

    XPathDocument is always read-only, whether you want to change a
    namespace or something else, it is not possible with an XPathDocument.
    Even with an XmlDocument it is not possible to simply change a namespace
    URI associated with an element or attribute node as the namespace is
    determined during creation of the node thus you have to create new
    elements or attributes in the proper namespace.
    An XSLT stylesheet is often helpful to transform an XML document to
    another XML format changing stuff like namespaces as needed.
    If you show us some example input and desired output then we can show
    you how to transform that with XSLT.


    --

    Martin Honnen --- MVP XML

    Comment

    • Rick

      #3
      Re: Change NameSpace Value on Selected Node

      I am fairly new to XML, but what I am doing is this, when creating an
      InfoPath form a manifest.xsf file is created the first node in the file is
      something like this:

      <xsf:xDocumentC lass trustSetting="a utomatic" dataFormSolutio n="yes"
      solutionVersion ="1.0.0.3" productVersion= "11.0.6357"
      solutionFormatV ersion="1.100.0 .0" publishUrl="E:\ InfoPath
      Documents\Curre ntSPInfo\manife st.xsf"
      name="urn:schem as-microsoft-com:office:info path:CurrentSPI nfo:-dataFormSolutio n"
      xmlns:xsf="http ://schemas.microso ft.com/office/infopath/2003/solutionDefinit ion"
      xmlns:msxsl="ur n:schemas-microsoft-com:xslt"
      xmlns:xd="http://schemas.microso ft.com/office/infopath/2003"
      xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance"
      xmlns:xdUtil="h ttp://schemas.microso ft.com/office/infopath/2003/xslt/Util"
      xmlns:xdXDocume nt="http://schemas.microso ft.com/office/infopath/2003/xslt/xDocument"
      xmlns:xdMath="h ttp://schemas.microso ft.com/office/infopath/2003/xslt/Math"
      xmlns:xdDate="h ttp://schemas.microso ft.com/office/infopath/2003/xslt/Date"
      xmlns:tns="http ://schemas.Converg enceComm.com/SPInfo/IPLists"
      xmlns:dfs="http ://schemas.microso ft.com/office/infopath/2003/dataFormSolutio n"
      xmlns:my="http://schemas.microso ft.com/office/infopath/2003/myXSD/2005-05-10T11:05:30"
      xmlns:ns1="http ://schemas.Converg enceComm.com/SPInfo/IPLists/Query"
      xmlns:soap="htt p://schemas.xmlsoap .org/soap/envelope/"
      xmlns:xsd="http ://www.w3.org/2001/XMLSchema"
      xmlns:mime="htt p://schemas.xmlsoap .org/wsdl/mime/"
      xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/"
      xmlns:soapenc=" http://schemas.xmlsoap .org/soap/encoding/"
      xmlns:ns2="http ://schemas.xmlsoap .org/wsdl/soap/"
      xmlns:http="htt p://schemas.xmlsoap .org/wsdl/http/"
      xmlns:wsdl="htt p://schemas.xmlsoap .org/wsdl/">

      I need to open this first node find the "my" namespace(highl ighted in Red)
      and change the value.

      Thanks.


      "Martin Honnen" <mahotrash@yaho o.de> wrote in message
      news:ODbYM%23XV FHA.2572@TK2MSF TNGP14.phx.gbl. ..[color=blue]
      >
      >
      > Rick wrote:
      >[color=green]
      >> I have an XML document that is generated from Infopath, I need to change
      >> the value of a namespace that is defined in a node in the form:
      >> <xsf:xDocumentC lass "xmlns:my=value here">.
      >> when i navigate to the namespace value it is read only and cannot be
      >> changed. Can anyone tell me how to change this value?
      >>
      >> My Code:
      >>
      >> Dim sSingleNode As XmlNode = objDoc.SelectSi ngleNode("//xsf:Node",
      >> NamespaceManage r)
      >> Dim nav As XPathNavigator
      >> Dim docNav As XPathDocument
      >> docNav = New XPathDocument(s File)
      >> nav = docNav.CreateNa vigator
      >> nav.MoveToRoot( )
      >> nav.MoveToFirst Child()
      >> nav.MoveToNext( )
      >> nav.MoveToFirst Namespace()
      >> Do
      >> If nav.Name.ToUppe r = "MY" Then
      >> nav.Value = Value 'Change value here
      >> End If
      >> Loop While nav.MoveToNextN amespace[/color]
      >
      > XPathDocument is always read-only, whether you want to change a namespace
      > or something else, it is not possible with an XPathDocument.
      > Even with an XmlDocument it is not possible to simply change a namespace
      > URI associated with an element or attribute node as the namespace is
      > determined during creation of the node thus you have to create new
      > elements or attributes in the proper namespace.
      > An XSLT stylesheet is often helpful to transform an XML document to
      > another XML format changing stuff like namespaces as needed.
      > If you show us some example input and desired output then we can show you
      > how to transform that with XSLT.
      >
      >
      > --
      >
      > Martin Honnen --- MVP XML
      > http://JavaScript.FAQTs.com/[/color]


      Comment

      Working...