0

I started this based on a previous discussion on this site: Find Sibling Attribute in XML document

I am working with Wonderware as well and have a string reader I am using to retrieve the tags I need. My string looks like this:

<ItemsList>
    <Item Name="soapsystemstaus" Alias="112MIX622_TIME.Barbe_Soap"/>
    <Item Name="strSystemDateTime" Alias="112MIX622_TIME.NowMinute"/>
</ItemsList>

This is the code I am trying to run:

dim ItemDBXMLString as string;
dim doc as System.Xml.XmlDocument;      
dim SR as System.IO.StringReader;
dim XdbInd as indirect;

XdbInd.BindTo( Me.DIO.Name + "." + Me.DIO.ScanGroup + ".AliasDatabase" );
ItemDBXMLString = XdbInd;

doc = new System.Xml.XmlDocument;   

SR = new System.IO.StringReader(ItemDBXMLString);

try
    doc.Load(SR);
    LogMessage(System.String.Format("SR Loaded into doc! <<<=== ******"));

Note: Indirect is a type of variable that can be used as a pointer to reference other area contents so basically:

XdbInd.BindTo( Me.DIO.Name + "." + Me.DIO.ScanGroup + ".AliasDatabase" );
ItemDBXMLString = XdbInd;

creates a reference to a memory area that contains the string I displayed at the beginning of this post. How to load this string into the Xml Document is the reason for my question. When I get to the instruction: "doc.Load(SR);" i receive an error:

System.Xml: The URL cannot be empty. Parameter name: url

In my ignorance, I never knew I HAD to specify an url in order to read Xml, always thought Xml was a data transport tool. Has anyone else had a similar error when trying to load Xml inside a XmlDocument? Any help or hint is greatly appreciated. (The reason for the full declaration of System.IO.StringReader etc. is due to the lack of Imports in the Wonderware scripting language. Besides the language, it supports .Net framework 4.5)

4
  • Use Parse(string) instead of Load(filename) Commented Aug 14, 2017 at 14:19
  • I am not sure to follow you. the XmlDocument class does not have a parse method. Can you elaborate on that please? Commented Aug 14, 2017 at 17:51
  • Looks like you really just want to load a string, not an actual file. Use doc.LoadXml Commented Aug 14, 2017 at 19:18
  • I actually tried both methods: The error I received on doc.Load( was: System.Xml.XmlException: Root element is missing. When I tried doc.LoadXml( System.Xml.XmlException: Data at the root level is invalid. Line 1, position 1. Commented Aug 14, 2017 at 20:33

1 Answer 1

1

OK so finally found how to (thanks to all and especially vintastic):

dim ItemDBXMLString as string;
dim SR as System.IO.StringReader; 
dim doc as System.Xml.XmlDocument;
dim XmlString as System.String;
dim XdbInd as indirect;

XdbInd.BindTo( Me.DIO.Name + "." + Me.DIO.ScanGroup + ".AliasDatabase" );
ItemDBXMLString = XdbInd;

doc = new System.Xml.XmlDocument();
SR = new System.IO.StringReader(ItemDBXMLString);

doc.LoadXml(ItemDBXMLString);
root = doc.DocumentElement; 
dim sTagTest as string;
dim sScanGroup as string;
sScanGroup = Me.DIO.ScanGroup;

' an = Field Attribute we are looking for
sTagTest = sScanGroup+isep+an;

'PLCTag = name of the tag on the PLC corresponding to 'an'
PLCTag = root.SelectSingleNode("/ItemsList/Item [translate(@Alias, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')='" + sTagTest.ToLower() + "']/@Name").InnerText;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.