|
can we convert from one structure of code to different one using xml technology...
suppose:
assembly code in xml form to c cod like in xml form
if its possible pls suggest me which xml technologies i should be looking into
thanx..
|
|
|
|
|
Hi, I have a windows application that calls a web service. Web service returns a string response like
<?xml version="1.0" encoding="utf-16"?>
<v1:ABCMerchant v1:tcid="11111" xmlns:v1="http://abc/2005/response">
<v1:ABCs>
<v1:ABC v1:ID="1" />
<v1:ABC v1:ID="2" />
</v1:ABCs>
</v1:ABCMerchant >
I have to parse this string and get the values returned in <v1:ABC V1:ID="1"
<v1:ABC v1:ID="2" /> etc.
Number of ids returned by web service will depend on ABC number being passed. if user passed let's say 10 as ABC number then 10 ID's will be returned with string <v1:ABC v1:ID="1" /> repeated 10 times with separatge Unique ID in each string.
I want to retrive these values from the string that I have up in this message.
How can I do that. Also, I am using vb.net. I would appreciate code sample in vb.net etc.
Thanks
Needy
|
|
|
|
|
Take the string that you get back and turn it into an XmlDocument:
Dim s as String = ...
Dim doc as XmlDocument = New XmlDocument()
doc.LoadXml(s)
The difficulty is in the namespace. You have to take a few extra steps to do an XPath:
Dim xnm as XmlNamespaceManager
xnm = new XmlNamespaceManager(doc.NameTable)
xnm.AddNamespace("v1", "http://abc/2005/response")
Dim nodes as XmlNodeList
nodes = doc.SelectNodes("//v1:ABCs/v1:ABC", xnm)
This gives you a collection of the "v1:ABC" nodes. Run that code and you'll see that nodes.Count is equal to the number of those "v1:ABC" nodes.
Logifusion[^]
|
|
|
|
|
it is giving me a null reference exception.
when i get a count on nodes selected, it gives me number of nodes correctly. However, when i try to loop through the node list i am not able to get the values of the nodes
Dim xNode As XmlNode
Dim ValuesString As String
For Each xNode In nodes
ValuesString = xNode.Attributes.GetNamedItem("v1:ABC").Value Next
I will want to receive these values and store them in database
Please let me know what is wrong with my code.
Line in bold is is where i am getting null reference exception.
Thanks
Needy
|
|
|
|
|
Instead of "v1:ABC", you should be asking for the attribute "v1:ID". That's the name of the attribute.
Logifusion[^]
|
|
|
|
|
I just found that out while debugging.
thank you so much for your response.
Out of curioucity, can I automatically fill up a datatable or dataset out of it? Because I will be calling a stored procedure to update the database with the ID values pulled from the xml string.
thanks a lot for your response.
I was stuck on this issue for a long time.
Thanks
Needy
-- modified at 16:38 Thursday 22nd June, 2006
|
|
|
|
|
Yes, you can create a DataSet off of the same string:
Dim ds As DataSet = New DataSet()
ds.ReadXml(New StringReader(s)) Where "s" is the string again. StringReader is in the System.IO namespace.
Just use the debugger to examine the contents of the DataSet . You'll see tables in there matching the XML elements.
|
|
|
|
|
<?xml version="1.0" encoding="utf-16"?>
<v1:ABCMerchant <b>v1:tcid="11111"</b> xmlns:v1="http://abc/2005/response">
<v1:ABCs>
<v1:ABC v1:ID="1" />
<v1:ABC v1:ID="2" />
</v1:ABCs>
</v1:ABCMerchant >
Hi, Dustin. I learned how to deal with node lists from your posts yesterday.
I apprecidate your help. I need to get the value in <b> </b> which is basically
v1:tcid="11111", Please shed the light again.
Thanks
Needy
|
|
|
|
|
Well, v1:ABCMerchant is your document element. You could either ask for the document element, or search for it with XPath.
doc.DocumentElement.Attributes("v1:tcid") -or- doc.SelectSingleNode("ABCMerchant", xnm).Attributes("v1:tcid")
You should do some reading up on XPath: http://www.w3schools.com/xpath/default.asp[^]
Logifusion[^]
|
|
|
|
|
i have a nested xml file and want this data in my database. but i read this xml file with the help of dataset
dataset.readxml("file path")
i got a error message
The same table (recordset) cannot be the child table in two nested relations.
I just want yo know how we manage this parent child relationship.
|
|
|
|
|
This is just the way that DataSets work. Let's say you have this XML:
<Company>
<Address>
...
</Address>
</Company>
<Customer>
<Address>
...
</Address>
</Customer>
This will throw an error because Address cannot be a child of both Company and Customer. You could change the table name from Address to Company_Address and Customer_Address and that will work.
Logifusion[^]
|
|
|
|
|
Hi,
iam new to xml.I have a xml document where i have to search for a string or keyword and display it in a datagrid.Plz help me
Regards,
david Boon.
|
|
|
|
|
When using DOM to process an XML file, I need to get hold of the attributes when present. Now I can get hold of them if I know there names, but what about when I do not know the attribute names?
Set objAttributes = objDOMNode.Attributes<br />
<br />
'check that there are attributes.<br />
If objAttributes.length > 0 Then<br />
<br />
'we know that we've named our id reference as<br />
''PERSONID', therefore tell the NameNodeListMap to get<br />
'this node by using the getNamedItem method<br />
Set objAttributeNode = objAttributes.getNamedItem("PERSONID")<br />
<br />
'store this value in the tag of the treeview<br />
tvwElement.Tag = objAttributeNode.nodeValue<br />
End If
The above code is OK for when you know the attribute name, but its the case when you dont know the number and names.
Any suggests please.
|
|
|
|
|
You need to loop through all elements checking what attributes they have and where.
Check this for XPath expressions:
[^].
Look for "Selecting Unknown Nodes"
Sincerely,
Elina
Life is great!!!
Enjoy every moment of it!
|
|
|
|
|
You can access this by using dataset
ds.ReadXml(XML FILE path);
j=0;
while(j
|
|
|
|
|
Hi everybody,
Iam having typical requiremnet .Let us suppose iam having an excel sheet which is consisting of 20columns and 10 rows.
I have one xml schema with me. NOw i have to create one xml file in which i have to insert whole first row elements (ie 20 elements).Like this i have to create 10 xml files as iam having 10 rows.These 20 elememts should go to appropriate positions in th XML file.The thing is that i have to do all this stuff in a single go or (a single click).
please give me suggestions how to create this scenario.
if u have a suggestion please do mail to "v.yekanth@tcs.com"
YEKANTH
|
|
|
|
|
it looks very simple if you are working in dot net. Open the connection with Excel file. and load the data in Dataset. and once you are in dataset you can save the XML file using Dataset.SaveXML(Path)
Rizwan Bashir
|
|
|
|
|
Hi - Is this a way to go about.
We have a text file with all data there is. I was able to convert this to text file using "XmlCsvReader Class". Now, I have to group this information, since it lists out all information as single xml records. There is some common information which needs to be grouped like all products for one common product_code needs to be as one record and not 3 records in XML file. How would I compare this information, more like compare nodes?
Is comparing this information in XML format fast or it is better to copy the text data into datatable, compare and then create XML document?
Thanks!
|
|
|
|
|
I have just started to learne about XML and need to write some software to help managed the exchange of data between different complaines.
I am unsure what to use for processing XML, i.e. Visual Basic 6 or using Visual Studio .Net and perhaps an MFC C++ application.
Any advice please and a site of a good example. I am quite happy with either.
|
|
|
|
|
What do you mean by processing? If you are looking for endpoints for different companies to send stuff to, then you might be better looking at webservices and an asp.net application...
|
|
|
|
|
hi,
i'm a newbie with XML and i need some help with my problem.
here it goes.. i'm trying to validate an xml document against an xml schema using the code below.. however, when in debug mode, i'm getting this error message (>> "object reference not set to an instance of an object" when i run thru this part of the code [>> while (vr.Read()); ]..
what am i missing here.. pls help...
thanks in advance...
lupin
here's the code:
public bool ValidateMapData(string strXMLDoc, string urlPath)
// (e.g. urlPath = "C:\MyXML\myschema.xsd")
{
bool isValidXml = true;
try
{
XmlSchemaCollection sc = new XmlSchemaCollection();
sc.ValidationEventHandler += new ValidationEventHandler(ValidationFailed);
sc.Add(null, urlPath);
if(sc.Count > 0)
{
StringReader sr = new StringReader(strXMLDoc);
XmlTextReader tr = new XmlTextReader(sr);
XmlValidatingReader vr = new XmlValidatingReader(tr);
vr.ValidationType = ValidationType.Schema;
vr.Schemas.Add(sc);
vr.ValidationEventHandler += new ValidationEventHandler(ValidationFailed);
while (vr.Read());
vr.Close();
if (errorCount > 0)
{
throw new Exception(errorMessage);
}
}
}
catch(Exception e)
{
myLog.Error(this, e.Message);
isValidXml = false;
}
return isValidXml;
}
public void ValidationFailed(object sender, ValidationEventArgs e)
{
myLog.Error(this, e.Message);
errorCount ++;
}
|
|
|
|
|
I'm not sure off hand what's happening in your code, but I have an example that's worked for me. strXMLDoc should be the full XML text, and urlPath should be the path to your schema, which I believe is what your example was expecting. Try this...
private System.Collections.Specialized.StringCollection errors =
new System.Collections.Specialized.StringCollection();
private System.Collections.Specialized.StringCollection warns =
new System.Collections.Specialized.StringCollection();
public bool ValidateMapData(string strXMLDoc, string urlPath) {
errors.Clear();
warns.Clear();
System.Xml.XmlTextReader tr = new System.Xml.XmlTextReader(new System.IO.StringReader(strXMLDoc));
System.Xml.XmlValidatingReader vr = new System.Xml.XmlValidatingReader(tr);
try {
vr.Schemas.Add(System.Xml.Schema.XmlSchema.Read(new System.IO.StringReader(urlPath),
new System.Xml.Schema.ValidationEventHandler(MessageHandler)));
vr.ValidationType = System.Xml.ValidationType.Schema;
} catch (Exception ex) {
while (ex != null) {
errors.Add(ex.Message);
ex = ex.InnerException;
}
}
try {
while(vr.Read());
} catch (Exception ex) {
while (ex != null) {
errors.Add(ex.Message);
ex = ex.InnerException;
}
}
string msgs = string.Empty;
foreach (string s in errors) {
msgs += "\r\nError: " + s;
}
foreach (string s in warns) {
msgs += "\r\nWarning: " + s;
}
if (errors.Count > 0) {
msgs = "Errors validating..." + msgs;
MessageBox.Show(this, msgs, "Schema validation", MessageBoxButtons.OK, MessageBoxIcon.Error);
} else if (warns.Count > 0) {
msgs = "Warnings validating..." + msgs;
MessageBox.Show(this, msgs, "Schema validation", MessageBoxButtons.OK, MessageBoxIcon.Warning);
} else {
return true;
}
return false;
}
private void MessageHandler(object sender, System.Xml.Schema.ValidationEventArgs args) {
if (args.Severity == System.Xml.Schema.XmlSeverityType.Error) {
errors.Add(args.Message);
} else {
warns.Add(args.Message);
}
}
Visit BoneSoft.com
|
|
|
|
|
I'm using C# in VS2005 to do some XPath queries. I've created my XPath statement using XMLSpy and it is something like:
//Unit/concat(productCode, ":", serialNumber)
I also tried with string-join, but I get the same error when I try it in my C# code:
Unhandled Exception: System.Xml.XPath.XPathException: '//Unit/concat(productCode,":",serialNumber)' has an invalid token.
Surely the concat function exists in the .net xpath library, am I doing something wrong?
The code around this is the standard routine:
<br />
xpathDoc = new XPathDocument(Filename);<br />
xpathNav = xpathDoc.CreateNavigator();<br />
xpathIter = xpathNav.Select(XPathString);<br />
- loop through the results etc -<br />
I hope someone has some pointers as to what could be wrong
Thanks
|
|
|
|
|
Hi I create a XML File In Memory But I have problem
Using XMLDoc.Load(M) to load that file that i have created
How Can i SuccessfulLy Load Back as i need to convert the XMlFile to string
Need Helps
Thanks A Million
KaKaShi HaTaKe
-- modified at 23:15 Thursday 15th June, 2006
|
|
|
|
|
Hi I have a problem of creating a XML file in the Memory Stream
Cos after i created it i will need to retreive it and convert it back to string
Dim m As New MemoryStream
Dim XmlDoc As New XmlDocument
Dim XmlNL As XmlNode
Dim yo As String
Dim textWriter As XmlTextWriter = New XmlTextWriter(m, System.Text.Encoding.UTF8)
textWriter.WriteStartDocument()
textWriter.WriteStartElement("ns0", "HCNET_ACK_Root", "http://HoHOHo.PCNET.IB.Schema.ExternalSchema.PCNET_ACK")
textWriter.WriteStartElement("BVN")
textWriter.WriteStartElement("SendingPerson", "")
textWriter.WriteString("Terry")
textWriter.WriteEndElement()
textWriter.WriteEndElement()
textWriter.Close()
XmlDoc.Load(m) The Problem Occur Here and The Error Stated
The root element is missing. at System.Xml.XmlTextReader.Read()
Pls Help
Really need help
Thanks A Million
KaKaShi HaTaKe
-- modified at 22:26 Thursday 15th June, 2006
|
|
|
|