I am pulling my Data using SQL to LINQ with XML Output and everything is working properly, except I am trying to add a counter under the select statement. Under New XElement("Message", "i") I need the i replaced with a 1, 2, 3... to reflect the number count of each data loop. My current output returns i for messageID and code is below using VB. I have struggled to find a solution any help would be appreciated.
i 'Need i as 1
Update
000076
0
i 'Need i as 2
Update
000104
0
Public Sub QOHPush()
Dim db As MYDataContext = New MYDataContext()
Dim QOH1 = <MyEnvelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="amzn-envelope.xsd">
<Header>
<DocumentVersion>1.01</DocumentVersion>
<MerchantIdentifier>Test</MerchantIdentifier>
</Header>
<MessageType>Inventory</MessageType>, _
<%= From c In db.Inventories _
Select New XElement("Message", _
New XElement("MessageID", "i"), _
New XElement("OperationType", "Update"), _
<Inventory>
<SKU><%= c.LocalSKU %></SKU>
<Quantity><%= c.QOH %></Quantity>
</Inventory>) %>
</MyEnvelope>
QOH1.Save("\\10.x.x.x\Backup\Products20110328134844.xml")
Have you considered this?
Dim QOH1 = <MyEnvelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="amzn-envelope.xsd">
<Header>
<DocumentVersion>1.01</DocumentVersion>
<MerchantIdentifier>Test</MerchantIdentifier>
</Header>
<MessageType>Inventory</MessageType>, _
<%= Dim counter as Integer = 0
From c In db.Inventories _
Select New XElement("Message", _
New XElement("MessageID", "i += 1"), _
New XElement("OperationType", "Update"), _
<Inventory>
<SKU><%= c.LocalSKU %></SKU>
<Quantity><%= c.QOH %></Quantity>
</Inventory>) %>
</MyEnvelope>
QOH1.Save("\\10.x.x.x\Backup\Products20110328134844.xml")
Related
I am using the functions below.In the first one i have parsed the node of xml and its value using MSXML. similar func fr other xml.i want to use two nodevalues and highlight it.i tried something.but i am getting error in the line highlighted(**) as 'Object Required'.your quick reply will help me more.
Public Sub DisplayNode1(ByRef Nodes1 As MSXML2.IXMLDOMNodeList, _
ByVal Indent1 As Integer)
some lines
RichTextBox2.Text = Space$(Indent) & xNode1.ParentNode.nodeName & _
":" & xNode1.NodeValue
difference
some lines
Public Sub difference()
Dim a As IXMLDOMText
Dim b As IXMLDOMText
a.NodeValue = xNode.innertext 'i get erroe in line
b.NodeValue = xNode1.innertext
If StrComp(a, b) > 0 Then
a = vbRed
b = vbRed
End If
please help me soon.
There is a lot that is potentially wrong with this.
xnode isn't declared anywhere in your code sample
Neither a, b, or xnode are explicitly set anywhere in your code sample
Unless xnode is a form/module/global level variable then it will be out of scope in the Difference procedure
It's not shown but I'm guessing that you don't have Option Explicit set in your code or by default
You'll need to address these points first before you can get anywhere with this code.
I have xml that looks like this:
<Doc>
<Thing>
<ID type="One">Fred</ID>
</Thing>
<Thing>
<ID>Bill</ID>
</Thing>
<Thing>
<ID type="Two">John</ID>
</Thing>
</Doc>
I can write LINQ to find the type="One" nodes. (or type="Two")
Dim ThingList As IEnumerable(Of XElement) = _
From el In doc...<Thing>.<ID> _
Where el.Attribute("type").Value = "One" _
Select el
How would I write a linq query to find the ID node that doesn't have a type attribute at all?
You should use the fact that Attribute() will return null/nothing if there's no such attribute.
In C# I would use:
var idsMissingType = doc.Descendants("ID") // Or whatever
.Where(x => x.Attribute("type") == null);
My guess is that the VB you want is:
Dim ThingList As IEnumerable(Of XElement) = _
From el In doc...<Thing>.<ID> _
Where el.Attribute("type") Is Nothing _
Select el
How to strip ALL HTML tags using MSHTML Parser in VB6?
This is adapted from Code over at CodeGuru. Many Many thanks to the original author:
http://www.codeguru.com/vb/vb_internet/html/article.php/c4815
Check the original source if you need to download your HTML from the web. E.g.:
Set objDocument = objMSHTML.createDocumentFromUrl("http://google.com", vbNullString)
I don't need to download the HTML stub from the web - I already had my stub in memory. So the original source didn't quite apply to me. My main goal is just to have a qualified DOM Parser strip the HTML from the User generated content for me. Some would say, "Why not just use some RegEx to strip the HTML?" Good luck with that!
Add a reference to: Microsoft HTML Object Library
This is the same HTML Parser that runs Internet Explorer (IE) - Let the heckling begin. Well, Heckle away...
Here's the code I used:
Dim objDocument As MSHTML.HTMLDocument
Set objDocument = New MSHTML.HTMLDocument
'NOTE: txtSource is an instance of a simple TextBox object
objDocument.body.innerHTML = "<p>Hello World!</p> <p>Hello Jason!</p> <br/>Hello Bob!"
txtSource.Text = objDocument.body.innerText
The resulting text in txtSource.Text is my User's Content stripped of all HTML. Clean and maintainable - No Cthulhu Way for me.
One way:
Function strip(html As String) As String
With CreateObject("htmlfile")
.Open
.write html
.Close
strip = .body.outerText
End With
End Function
For
?strip("<strong>hello <i>wor<u>ld</u>!</strong><foo> 1234")
hello world! 1234
Public Function ParseHtml(ByVal str As String) As String
Dim Ret As String, TagOpenend As Boolean, TagClosed As Boolean
Dim n As Long, sChar As String
For n = 1 To Len(str)
sChar = Mid(str, n, 1)
Select Case sChar
Case "<"
TagOpenend = True
Case ">"
TagClosed = True
TagOpenend = False
Case Else
If TagOpenend = False Then
Ret = Ret & sChar
End If
End Select
Next
ParseHtml = Ret
End Function
This is a simple function i mafe for my own use.
use Debug window
?ParseHtml( "< div >test< /div >" )
test
I hope this will help without using external libraries
I've got a query in C# that is working for me to query the metadata for the Entity Framework. I need to convert it to VB.NET, but I'm struggling to convert the AS keyword to "cast" meta to System.Data.Metadata.Edm.EntityType. I've tried TryCast, CType, Cast, etc.
Here's the query in C#:
var queryResult = from meta in oc.MetadataWorkspace.GetItems(System.Data.Metadata.Edm.DataSpace.CSpace)
.Where(m => m.BuiltInTypeKind == System.Data.Metadata.Edm.BuiltInTypeKind.EntityType)
from p in (meta as System.Data.Metadata.Edm.EntityType).Properties
.Where(p => p.DeclaringType.Name == entityClassType.Name
&& p.Name == propertyName)
select p;
This is the closest I've come to getting it to compile in VB.NET (the As keyword in underlined and says ')' expected:
Dim query2 = _
From meta In entityObjectContext.MetadataWorkspace.GetItems(System.Data.Metadata.Edm.DataSpace.CSpace) _
.Where(Function(m) m.BuiltInTypeKind = System.Data.Metadata.Edm.BuiltInTypeKind.EntityType) _
From p In (meta As System.Data.Metadata.Edm.EntityType).Properties _
.Where(Function(p) p.DeclaringType.Name = entity.GetType().Name _
And p.Name = propertyName) _
Select p
This is killing me. I'm so close...
You can use CType to type cast:
...
From p In CType(meta, System.Data.Metadata.Edm.EntityType).Properties _
...
Update: Looking again at the query, I would suggest using OfType() instead:
From meta In entityObjectContext.MetadataWorkspace.GetItems(System.Data.Metadata.Edm.DataSpace.CSpace) _
.OfType(Of System.Data.Metadata.Edm.EntityType)() _
From p In meta.Properties _
Where p.DeclaringType.Name = entity.GetType().Name _
And p.Name = propertyName _
Select p
Update 2: Also, it looks like GetItems() has a generic version that I suspect will return only items of your desired type:
From meta In entityObjectContext.MetadataWorkspace.GetItems(Of System.Data.Metadata.Edm.EntityType)(System.Data.Metadata.Edm.DataSpace.CSpace) _
From p In meta.Properties _
Where p.DeclaringType.Name = entity.GetType().Name _
And p.Name = propertyName _
Select p
If I were writing this query in VB.NET, I would do it like this without the lambdas. I think it's easier to read, but they way you're doing it would probably be easier for a C# developer to read.
Dim query2 = _
From meta In entityObjectContext.MetadataWorkspace.GetItems(System.Data.Metadata.Edm.DataSpace.CSpace) _
Where m.BuiltInTypeKind = System.Data.Metadata.Edm.BuiltInTypeKind.EntityType _
From p In CType(meta, System.Data.Metadata.Edm.EntityType).Properties _
Where p.DeclaringType.Name = entity.GetType().Name _
And p.Name = propertyName) _
Select p
I've been looking after this for months now and I mostly found sites asking the same question.
The answers I did found were always for .NET or C++ or involved XSLT.
After months of research I've come up with this.
Public Function PrettyPrintXML(XML As String) As String
Dim Reader As New SAXXMLReader60
Dim Writer As New MXXMLWriter60
Writer.indent = True
Writer.standalone = False
Writer.omitXMLDeclaration = False
Writer.encoding = "utf-8"
Set Reader.contentHandler = Writer
Set Reader.dtdHandler = Writer
Set Reader.errorHandler = Writer
Call Reader.putProperty("http://xml.org/sax/properties/declaration-handler", _
Writer)
Call Reader.putProperty("http://xml.org/sax/properties/lexical-handler", _
Writer)
Call Reader.parse(XML)
PrettyPrintXML = Writer.output
End Function
Using a document:
Public Function PrettyPrintDocument(Doc As DOMDocument60) As String
PrettyPrintDocument = PrettyPrintXML(Doc.XML)
End Function