1

私の最初の投稿、うーん!私はVBAを学んでいて、多くの進歩を遂げてきたので、過去6か月間潜んでいました. でも今、私は立ち往生していて、あなたの助けが必要です!

上部の宣言を別の宣言に置き換える必要がある xml ドキュメントのセットがありますが、これを行う方法がわかりません。VBA で DOMDocument を使用して xml ドキュメントを変更する方法に関する多くの記事を読み、Microsoft API を使用して xml ファイル内のさまざまなノードを変更する方法を理解しました。ただし、宣言にアクセスできないようです。

これは可能ですか?

もしそうなら、私は正しい軌道に乗っていますか?

その場合、xml ファイル内の宣言にアクセスして変更できるようにするには、どのプロパティまたはメソッドを呼び出す必要がありますか (存在する場合)。

そうでない場合、どうすればいいですか?

手動でコピーして貼り付けることは本当に避けたいと思います。変更が必要なレコードは何千もあります。

フィールドをプルして変更するための私のVBAは次のとおりです。

Sub XMLtest()
    Dim strXML As String
    Dim objXML As MSXML2.DOMDocument
    Dim point As IXMLDOMNode
    Dim origVal As String
    Dim newVal As String

    Set objXML = New MSXML2.DOMDocument

    strXML = "Q:\TIS\!Safety(Beth)\Tim's Projects\Safety Inspections\xml\2011-12-07T10_32_31(good tag).xml"

    objXML.Load (strXML)

    Set point = objXML.DocumentElement.ChildNodes.Item(0)
    Debug.Print point.XML

    origVal = objXML.DocumentElement.ChildNodes.Item(0).Text
    MsgBox origVal

    'this is a section that will change the value of the first item
    objXML.DocumentElement.ChildNodes.Item(0).Text = "TimTest1"
    MsgBox objXML.DocumentElement.ChildNodes.Item(0).Text

    objXML.Save (strXML)

End Sub

私の目標は、xml ファイルの宣言部分を削除し、それを別の一連の宣言に置き換えて、再び infopath で読み取れるようにすることです (現在の宣言は infopath フォームでは読み取られません)。

削除したい宣言:

<?xml version="1.0" encoding="UTF-8"?>
<?mso-infoPathSolution name="urn:schemas-microsoft-com:office:infopath:Office-Inspection:-myXSD-2011-10-05T14-49-56" PIVersion="1.0.0.0" href="http://a.octer.com/dept/TIS/TISSafety/Office%20Inspection/Forms/template.xsn" solutionVersion="1.0.0.31" productVersion="14.0.0" ?>

<?mso-application progid="InfoPath.Document" versionProgid="InfoPath.Document.2"?>

<my:myFields xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dfs="http://schemas.microsoft.com/office/infopath/2003/dataFormSolution" xmlns:tns="http://microsoft.com/webservices/SharePointPortalServer/UserProfileService" xmlns:s1="http://microsoft.com/wsdl/types/" xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2011-10-05T14:49:56" xmlns:xd="http://schemas.microsoft.com/office/infopath/2003" xml:lang="en-us">  

変更しようとしている xml ドキュメントを次に示します。

<?xml version="1.0" encoding="UTF-8"?>
<?mso-infoPathSolution name="urn:schemas-microsoft-com:office:infopath:Office-Inspection:-myXSD-    2011-10-05T14-49-56" PIVersion="1.0.0.0" href="http://a.octer.com/dept/TIS/TISSafety/Office%20Inspection/Forms/template.xsn" solutionVersion="1.0.0.31" productVersion="14.0.0" ?>

<?mso-application progid="InfoPath.Document" versionProgid="InfoPath.Document.2"?>

<my:myFields xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dfs="http://schemas.microsoft.com/office/infopath/2003/dataFormSolution" xmlns:tns="http://microsoft.com/webservices/SharePointPortalServer/UserProfileService" xmlns:s1="http://microsoft.com/wsdl/types/" xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2011-10-05T14:49:56" xmlns:xd="http://schemas.microsoft.com/office/infopath/2003" xml:lang="en-us">  

<my:Manager>MikeTest2</my:Manager>
<my:Date>2011-12-07</my:Date>
<my:Team>Marketing</my:Team>
<my:Inspector>HermanTest3</my:Inspector>
<my:Aisles>Y</my:Aisles>
<my:SecondaryAisles>Y</my:SecondaryAisles>
<my:CircutOverload>Y</my:CircutOverload>
<my:OutletCovers>Y</my:OutletCovers>
<my:PanelsClosed>Y</my:PanelsClosed>
<my:FireExt>Y</my:FireExt>
<my:ExtTag>Y</my:ExtTag>
<my:CeilingTiles>Y</my:CeilingTiles>
<my:Sprinklers>Y</my:Sprinklers>
<my:Evacuation>Y</my:Evacuation>
<my:a44444>Y</my:a44444>
<my:Comments>email sent to team encouraging a general cleanup of floor space in cubicles.</my:Comments>
</my:myFields>
4

1 に答える 1

2

だから私は答えを見つけました:

msxml アドオンの使用方法については、こちらの API をさらに読む必要があります: http://msdn.microsoft.com/en-us/library/ms766487

その時点で、VBA の次の行を使用して宣言にアクセスしました。

objXML.ChildNodes.Item(0)

これは最初の宣言です:

<?xml version="1.0" encoding="UTF-8"?> 

基本的に、DOM ドキュメントの構造と、ノードとそのプロパティの使用について学ぶ必要がありました。うまくいけば、これが将来この答えを探している他の人に役立つでしょう。

于 2012-07-27T22:12:04.297 に答える