How to: SolutionXMLElement

T

TC

Hey All,

I am trying to figure out or find a sample or determine if it is possible to
use the 'SolutionXMLElement' method to add / read custom data added to a
Visio document.

While I've seen some discussions, I have not seen any tangible, working
samples.

For example, I would like to do something like the following:

MyVisDoc.SolutionXMLElement("CustomXML") = "CustomValue"
MsgBox MyVisDoc.SolutionXMLElement("CustomXML")

Unfortunately, the above does not work.

Can anyone provide a working sample or link to a working sample?

Thanks,

TC
 
D

David Parker

The Visio SDK Code Samples under Integration / Data Storage in Solution XML
gives you sample code.
You will then be able to do:

SetDocumentXml MyVisDoc, "CustomXML", "CustomData"

or similar....
 
T

TC

Hey David,

I downloaded the SKD for Visio 2003 and I did not see any section called
"Integration / Data Storage".

I also performed a search of the entire SDK branch for 'SolutionXMLElement'
and 'SetDocumentXml' and I only received a couple of hits on the former
under a couple of C++ files. No VBA.

To which SDK do you refer?

Thanks,

TC
 
A

Al Edlund

VBA is close enough to VB6 that you should be able to work with the VB6
examples . The xml examples show how to save/load xml into the visio
document. The assumption is that if you are asking to play with xml in
visio, you already understand visio and xml coding to start with. There are
plenty of examples of how to manipulate xml on msdn since that is not unique
to Visio.

this is an example of manipulating an xml image of a v2007 datarecordset.

al

'
' we pass in the xml version of the recordset
' the recordid, the columnnid, and the new value for the field
' then return the updated xml image of the recordset
'
Public Function setXmlRecordData _
(ByVal strXmlIn As String, _
ByVal lngRowID As Long, _
ByVal lngColId As Long, _
ByVal strValue As String) _
As String

On Error GoTo ErrHandler

Dim strXmlOut As String
Dim docXmlIn As DOMDocument60
Set docXmlIn = New DOMDocument60
' this is the parent of the record node
Dim ndeRecords As IXMLDOMNode
' this is the record node
Dim ndeFind As IXMLDOMNode
' this is the updated record node
Dim ndeNew As IXMLDOMNode
Dim attrFind As IXMLDOMAttribute

Dim strfind As String
' xml60 / visio complains about this xpath format
' strFind = "/xml/rs:data/z:row/@ndeName"
' so we use something like this one instead
' strFind = "//*/*[@ndeName = '01001-a-1-a-1-3550-2']"
' load the document with the string
strfind = "//*/*/*[@c0 = " & lngRowID & "]"

If docXmlIn.LoadXML(strXmlIn) Then
' find row
Set ndeFind = docXmlIn.SelectSingleNode(strfind)
Set ndeRecords = ndeFind.ParentNode

Set ndeNew = ndeFind
Set attrFind = ndeNew.Attributes.Item(lngColId)
attrFind.Value = strValue

ndeRecords.replaceChild ndeNew, ndeFind

setXmlRecordData = docXmlIn.XML

Set docXmlIn = Nothing
Exit Function
Else

' The document failed to load.
Dim strErrText As String
Dim xPE As MSXML2.IXMLDOMParseError
' Obtain the ParseError object
Set xPE = docXmlIn.parseError
If xPE.ErrorCode <> 0 Then
With xPE
strErrText = "Your XML Document failed to load" & _
"due the following error." & vbCrLf & _
"Error #: " & .ErrorCode & ": " & xPE.reason & _
"Line #: " & .Line & vbCrLf & _
"Line Position: " & .linepos & vbCrLf & _
"Position In File: " & .filepos & vbCrLf & _
"Source Text: " & .srcText & vbCrLf & _
"Document URL: " & .URL
End With
MsgBox strErrText, vbExclamation
End If

End If

Set xPE = Nothing
Set docXmlIn = Nothing
setXmlRecordData = ""
Exit Function

ErrHandler:

MsgBox Err.Description
'return empty string
setXmlRecordData = ""

End Function
 
D

David Parker

I was referring to the Visio 2007 SDK .. the example VB6 code should work in
Visio 2003
 
T

TC

Hey Guys,

There seems to be some confusion regarding what I am trying to do.

There are XML properties in the Visio VBA object model. Such a property is
stated in the Subject of this post.

Are you saying that I should be using different libraries (i.e. the standard
XML libraries)?

I will also add that I searched MSDN as well as the SDK for the the property
mentioned in the Subject of this post unsuccessfully.

The 4 properties to which I refer are:

SolutionXMLElement
SolutionXMLElementCount
SolutionXMLElementExists
SolutionXMLElementName

Does anyone have working VBA samples that utilize the above properties to
read, add, update, etc. a Visio Doc's XML DOM?

Are the above 4 properties frowned upon in terms of use?

Thanks,

TC
 
T

TC

Hey Guys,

I should also mention something else for clarity.

The 4 properties within the Visio object model that I mention which relate
to XML are associated with the Visio 'Document' object.

What I am trying to do is add some custom XML tags or attributes and
associated values to the 'Document'.

Visio does not allow for CustomDocumentProperties and I would like to
material to a Document via XML if such a thing is possible.

Thanks,

TC
 
D

David Parker

If you store the document in Visio XML (ie as a VDX) then you can use the
document SolutionXML to read\write values without opening Visio - just use
standard XML DOM.
If you are using the Visio object model, then add a reference to MSXML and
use the code in the SDK
 
T

TC

Hey David,

I did find the following in the SDK documentation:

vsoDocument.SolutionXMLElement("SomeName") = _
"<SolutionXML Name='SomeName' xmlns:mysol='sol'><mysol:myXML> value

</mysol:myXML></SolutionXML>

However, when use the following, for example:

MsgBox docVisDoc.SolutionXMLElement("SomeName")

Instead of getting "value" in the msgbox, I get the entire XML string.

I've looking for a way to load the <VisioDocument> into a DOMDocument but
have not found anything in the documentation, etc. to suggest this.

How do I extract just the value that I placed in that custom element? I
appear to missing something ;-)

Best,

TC
 
D

David Parker

When you install the SDK, it appears as a program menu under 200x Office
System Developer / Microsoft Office 200x SDK / MIcrosoft Office Visio Code
Samples
 
D

David Parker

Did you follow theGetDocumentXml code snippet?

TC said:
Hey David,

I did find the following in the SDK documentation:

vsoDocument.SolutionXMLElement("SomeName") = _
"<SolutionXML Name='SomeName' xmlns:mysol='sol'><mysol:myXML> value

</mysol:myXML></SolutionXML>

However, when use the following, for example:

MsgBox docVisDoc.SolutionXMLElement("SomeName")

Instead of getting "value" in the msgbox, I get the entire XML string.

I've looking for a way to load the <VisioDocument> into a DOMDocument but
have not found anything in the documentation, etc. to suggest this.

How do I extract just the value that I placed in that custom element? I
appear to missing something ;-)

Best,

TC
 
A

Al Edlund

IMHO you're not missing anything. Visio gives you the ability to save an xml
string, of some unknown content, within either the document (or a visio
cell). It is up to the programmer (you?) to provide the schema for that
content and the methods to parse the information from the xml string.
Al
 
T

TC

Hey David,

Yes! Thanks for the help.

Al, indeed, I WAS missing something. I was looking in the wrong place for
the wrong thing.

Instead looking in the actual physical project samples that come with the
SDK or SDK Documentation, I needed to look within the Code Librarian Viewer.

There and only there was I able to finally find the 'GetDocumentXml' sample
to which David refers.

Thanks Again Guys,

Todd
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top