|
Ok, I wasn't sure what board to put this so I am shooting here first as it is a c# code question:
I have the following XML Data that is returned from a 3rd party API. The resulting data is stored as a string and loaded into the XML dom as follows:
// s_invoices contains the XML
string s_invoices;
XmlDocument doc = new XmlDocument();
doc.InnerXml = s_invoices;
XmlElement root = doc.DocumentElement;
The XML itself looks like the following (sample):
<?xml version="1.0" encoding="UTF-8"?>
<Order_Invoice_Outgoing_Array_Element>
<Order_Invoice_Outgoing_Element>
<interface_transaction>18399</interface_transaction>
<transaction>18399</transaction>
<order_Invoice_Header>
<vendor>P00621</vendor>
<invoice>90951282</invoice>
<currency>USD</currency>
<invoice_Category>ORDER</invoice_Category>
<invoice_Date>2003-08-18T00:00:00.000-04:00</invoice_Date>
<invoice_Due_Date>2003-0818T00:00:00.00004:00</invoice_Due_Date>
<terms>NET30</terms>
<invoice_Amount_Total>6260</invoice_Amount_Total>
<status>CLOSED</status>
<currency_Exchange_Rate>1</currency_Exchange_Rate>
<order_Type_Optional>PO</order_Type_Optional>
<order_Number_Optional>40845</order_Number_Optional>
<pay_Indicator>AP</pay_Indicator>
<original_Invoice_Amount>0</original_Invoice_Amount>
<GL_Account>
<GL_Company>443120</GL_Company>
<GL_Expenditure>809</GL_Expenditure>
<GL>0</GL>
<GL_Cost_Center>0</GL_Cost_Center>
<GL_Description>REPAIR ORDERS</GL_Description>
<GL_Category>ALL</GL_Category>
<modified_By>GLACCOUNT</modified_By>
</GL_Account>
<voucher>78086</voucher>
<created_By>TGREEN</created_By>
<created_Date>2003-10-31T00:00:00.000-05:00</created_Date>
<modified_By>PFAPHSTN</modified_By>
<modified_Date>2006-03-19T00:00:00.000-05:00</modified_Date>
<line_Sum>6260</line_Sum>
<AP_System_Received_Flag>false</AP_System_Received_Flag>
<paid_Flag>true</paid_Flag>
<interface_Batch>14975</interface_Batch>
</order_Invoice_Header>
<order_Invoice_Lines>
<order_Invoice_Line>
<order_Type>PO</order_Type>
<order_Line>7</order_Line>
<order_Number>40845</order_Number>
<invoice_Category>ORDER</invoice_Category>
<invoice_Date>2003-08-18T00:00:00.000-04:00</invoice_Date>
<invoice_Amount>6260</invoice_Amount>
<invoiced_Qty>1</invoiced_Qty>
<GL_Account>
<GL_Company>443120</GL_Company>
<GL_Expenditure>809</GL_Expenditure>
<GL>0</GL>
<GL_Cost_Center>0</GL_Cost_Center>
<GL_Description>REPAIR ORDERS</GL_Description>
<GL_Category>ALL</GL_Category>
<modified_By>GLACCOUNT</modified_By>
</GL_Account>
<status>CLOSED</status>
<assigned_To>VHAINES</assigned_To>
<credit_Memo>78086</credit_Memo>
<credit_Memo_Cost>0</credit_Memo_Cost>
<original_Invoice_Amount>0</original_Invoice_Amount>
<created_By>TGREEN</created_By>
<created_Date>2003-10-31T00:00:00.000-05:00</created_Date>
<modified_By>PFAPHSHD</modified_By>
<modified_Date>2006-03-19T08:39:39.000-05:00</modified_Date>
<line_Amount>6260</line_Amount>
</order_Invoice_Line>
</order_Invoice_Lines>
</Order_Invoice_Outgoing_Element>
</Order_Invoice_Outgoing_Array_Element>
So basically it is a very convoluted XML string. Now what I want to do is populate the XML into a form but am having problems finding what I am looking for.
I am currently using the following:
Console.WriteLine(" The terface_transaction : {0}", root.GetAttribute("//Order_Invoice_Outgoing_Array_Element/Order_Invoice_Outgoing_Element/interface_transaction"));
To try to write out just the interface transaction portion of the XML but alas it is not working. I am thinking it is because maybe GetAttribute is set to start at root and somehow my pathing is wrong, any ideas?
-- modified at 11:22 Tuesday 18th April, 2006
|
|
|
|
|
// s_invoices contains the XML
string s_invoices;
XmlDocument doc = new XmlDocument();
doc.LoadXml(s_invoices);
string xpath =
"/Order_Invoice_Outgoing_Array_Element" +
"/Order_Invoice_Outgoing_Element" +
"/interface_transaction/child::text()";
XmlElement root = doc.DocumentElement;
XmlText interface_transaction =
(XmlText)root.SelectSingleNode(xpath);
if (interface_transaction != null)
{
Console.WriteLine(interface_transaction.Value);
}
Please note that "interface_transaction" is an element node not an attribute node.
|
|
|
|
|
Hi
I am developeing a web application in asp.net using vb.net and vbscript. In this I need XML data manipulation from server side to client side. I get data from Serverside ie
/*
txtXML= ds.getxml() 'here txtXML is hidden text box.
*/
and in client side
/*
strXML= document.Form1.txtXML.value
set objXMLDoc= CreateObject("Microsoft.XMLDom")
objXMLDoc.async= "false"
objXMLDoc.loadXML(strXML)
set ElementList = objXMLDoc.getElementsByTagName("Customers")
for i=0 to ElementList.length - 1
set objElementChild= ElementList.item(i).childnodes.item(1)
MsgBox objElementChild.text
next
*/
Here the problem is user can view all the xml data stored in the hidden text box. If he right click web page and click view source, he can view whole xmldata. I want to hide these data from user, and dont want to store any wehre else in the physical location.
Can i directly access any node from xml file ie parent node or child node or its attribute.
Please help me... with example project.
<NewDataSet>
<Customers id="001">
<Name>
<Fname>Maximas</Fname>
<Lname>Shel</Lname>
</Name>
<Sex>Male</Sex>
</Customers>
........
........
</NewDataSet>
can i access/ search any node from this xml like (fname,sex) and manipulate lname or sex for particular node.
Please help me... it is very urgent... i am in big trouble.....
Maximasshel
|
|
|
|
|
Does it have to be done on the client side in this fashion?
|
|
|
|
|
hi,
yes, i need it in client side, you can do it in your on ways both in server and client side(above specified code is just an example). We are using a client grid and it doesnot require posting. The reason is that loading thousands of data in each posting is difficult. Now i am maintaing a string and populate client grid from that string. And based on this string i am doing various operation like add,edit,search, grouping etc. Now i came to know that xml data manipulation is easier than string manipulation.
So i need solution in client side. Just i tried transfer xml data from server to client side using hidden text box. but user can able to view the whole data. I dont want alow this.
If any one know the solution pls help me.
If there is any better way of populating and transfering xml data to client side is also acceptable.
Maximasshel
|
|
|
|
|
You can place your XML document on the web server and access it as follows:
<xml id="customer_id" src="http://www.codeproject.com/xmlFile.xml"></xml>
|
|
|
|
|
Hi All
I have both the XML and XSL files named: SummarizedLedgerReport.xml, SummarizedLedgerReport.xsl
I need to know how to convert these two files to PDF using FOP(Formatting Objects Processor). I'v read up on it but i'm still not shure how to go about it.
Any advice is more then welcome
|
|
|
|
|
i am using the following code to select rows in xml with a condition name = strVar:
"/accounts/account[name='"+strVar+"']/name"
my problem is,
how can i select rows with condition that name date is like strVar,
in SqlServer i use "select * from account where name like '%"+strVar+"%', but i ont know how it work with XML.
sultan
|
|
|
|
|
XPath has a few functions that may help:
contains - Returns true if the first argument string contains the second argument string; otherwise returns false.
starts-with - Returns true if the first argument string starts with the second argument string; otherwise returns false.
substring - Returns the substring of the first argument starting at the position specified in the second argument and the length specified in the third argument.
substring-after - Returns the substring of the first argument string that follows the first occurrence of the second argument string in the first argument string.
substring-before - Returns the substring of the first argument string that precedes the first occurrence of the second argument string in the first argument string.
string-length - Returns the number of characters in the string.
Example:
"/accounts/account[contains(name,'" + strVar + "')]/name"
Another option is to select all of the "account" nodes and then filter out unwanted selected nodes using regular expressions or string funtions in your favorite managed or unmanaged language.
|
|
|
|
|
Dear Mr George L. Jackson,
Thanks alot for your help, its exactlly what iam looking for and its work well.
Sultan
|
|
|
|
|
If i whant to search in more than one field in the same expression for ex:
i want to find the name of persons where they have middle name like 'Var1' and jobname like 'Var2'
So how can i use the apove expression ?
Sultan
|
|
|
|
|
You can use the "and", "or" or "not()" operators.
Example:
"/accounts/account[contains(middle,'" + Var1 + "') and contains(jobname,'" + Var2 + "')]/name"
Of course, you will have to use the appropriate XPath function to do the proper search.
|
|
|
|
|
dear George L. Jackson
I unable to thank you as due,
and in the end thank you very much.
sultan
|
|
|
|
|
I've used simple XSLT to convert XML to a web page but now I wonder how far can I go. That's why I want to ask a few questions what is possible.
Is it possible to create a full web site just using XML?
I want the transformations to occur on the server if possible. How can I do it. I have no idea at all. I have probably PHP support on the server (I'm not quite sure) but I can neither program it nor I want to learn it (except very basic stuff if needed) due to time constraints.
My goal is to create a web catalog that I feed with XML files about each product and images and they are displayed in particular order. So when I want to change something I just upload a new XML file or image. That's all. The goods won't be too many, maybe just a couple of hundereds or even much less.
Is this possible to create with XML/XSL/XSLT?
Which good modern book do you recommend me to read about that topic?
Thank you very much!
|
|
|
|
|
Cristoff wrote: Is it possible to create a full web site just using XML?
Yes and No.
You can define the content. But as you point out, it does need some xsl/xslt processing.
Cristoff wrote: but I can neither program it nor I want to learn it
I will say a big problem. Developing good xslt is programing really. (Or call it another art form.)
Your issue is what enviroment do you want to use. If you are serious that you do not have time. Then I think that is your answer, you do not have time. Really depends on what you call basic stuff.
Cristoff wrote: Is this possible to create with XML/XSL/XSLT?
Yes, very much so. Now which option to you want and what constraints do your clients force upon you?
Do a search on AJAX, and Apache Cocoon for some options. Now my guess is you do not have time for either. So what are you comfortable developing dynamic pages now? Select it, add xml processing and generate the basic pages just as you always have. Then add the content by getting the values of the xml element content from either the DOM or SAX models (for small and simpler to understand probably the DOM)
"Every new day begins with possibilities. It's up to us to fill it with things that move us toward progress and peace.” (Ronald Reagan)
|
|
|
|
|
I have to clarify a few things here first. I hope I'll succeed. I want to help you help me!
Michael A. Barnhart wrote: Cristoff wrote:
Is it possible to create a full web site just using XML?
Yes and No.
Michael A. Barnhart wrote: but I can neither program it nor I want to learn it
I will say a big problem. Developing good xslt is programing really. (Or call it another art form.)
I don't want to learn PHP but the server supports only PHP and MySQL. I'd rather use ASP.NET but it is not available.
I want to learn XSLT. My concern is if just XSLT and all other XML techs are enough for the job.
I know that IE 6, Firefox etc. have full support of XML, XSLT etc. so they can do the processing on the client side but I also want the site to be viewed by older browser so I need to process the date on the server. I just have no idea what is needed for the job. A special server or to program the processing in PHP, ASP.NET...
Michael A. Barnhart wrote: Your issue is what enviroment do you want to use. If you are serious that you do not have time. Then I think that is your answer, you do not have time. Really depends on what you call basic stuff.
Well, I don't want to learn PHP because that will be the first and the last project I'll ever do with it but I'll definitely have much more use just for XML/XSLT. I already have done a personal site with both technologies and it works fine (No you cannot view it, it is not on the web).
The site I'm working now is made mostly of static HTML pages + some JavaScript. I'm doing it with Dreamweaver. Once it is done I really have no time constraints to come up with a new version.
This time I would like to have all the data as XML that I can be created by another person manually.
Then when needed just the XML files are replaced without the need to change everything else (the way it is now).
If I had access to a server that supports .NET. I wouldn't have asked here at all.
|
|
|
|
|
Sounds like you are most of the way then. Assuming the arrangement of the page is basically static, you can output the html declarations (header and body wrapping elements) with either text output from PHP or the initial output from the xslt processing. Then you add the changing html (table rows, or what ever) via the matching loops you have with the xslt processing. The XSLT process does not have to output xml. You do not have to learn much php, just enough to read in the xml file and then start the xslt processing.
Cristoff wrote: If I had access to a server that supports .NET.
Same boat I am in right now. I have just about convinced myself to go with a different and more expensive service to add the capability.
"Every new day begins with possibilities. It's up to us to fill it with things that move us toward progress and peace.” (Ronald Reagan)
|
|
|
|
|
|
pls help me to find the coding for generating xml schema from vb.net without using data grid and datsset
|
|
|
|
|
Is it possible - using xpath - to count how many times a node appears???
Say I have
papers
paper
paper
paper
papers /
IS there a way in xpath to count the number of paper nodes? I.e. return 3?
/\ |_ E X E GG
|
|
|
|
|
i figured it out, the xpath count() function!!!??
/\ |_ E X E GG
|
|
|
|
|
Hi,
I have an xml file that is all on one line, it is well formed but I want to write it out indented.
From:
<fdt:supportedlanguages><fdt:languageid languageid="1033"><fdt:languageid languageid="1031">
To:
<fdt:supportedlanguages> <fdt:languageid languageid="1033"> <fdt:languageid languageid="1031">
Any help would be great.
Thanks
|
|
|
|
|
What langauge?
If .net then set the formatting option in the XmlTextWriter class.
XmlTextWriter w = new XmlTextWriter(Console.Out);
w.Formatting = Formatting.Indented;
This is from the MSDN library.
"Every new day begins with possibilities. It's up to us to fill it with things that move us toward progress and peace.” (Ronald Reagan)
|
|
|
|
|
hi i have an xml file...it is having structure like following
<node1>
<node2/>
<node3/>
<node4>
<node5/>
<node6/>
</node4>
<node7/>
</node1>
now what i want is that i create a datagrid wherein each column would be represented by nodes 2 to 7.....so that user can fill in the data for each column...and then on submit all the data gets transferred into innertexts of the respective element in in the xml file.............to summarize,i am trying to provide a user interface for filling in the innertext of an xml document......i need to do it urgently ..please help
-- modified at 8:32 Friday 7th April, 2006
|
|
|
|
|
Hi there,
Iam newbie for c# i like to know how we can load an xml file and read the node inside the xml file earlier my application use to call another appl to get txt file and read the node inside the text file. now i want to pass the xml file instead of the appl so the following are the existing code pls advice how i can do it
Crosswalk_Holdings.Holdings ObjHoldings = new Crosswalk_Holdings.Holdings();
string strresponse ="";
string strMarctxt = "";
XmlNode ObjMarcTxtNode;
//by me 8/2/06
//strresponse = ObjHoldings.SendReceiveXML("http://203.78.8.89/scripts/vista/usmarc11.pl",strBIDNoForHoldings);
XmlDocument ObjXMLHoldings = new XmlDocument();
ObjMarcTxtNode = ObjXMLHoldings.SelectSingleNode("//USMARC/TXT");
if(ObjMarcTxtNode!=null)
{
if (ObjMarcTxtNode.InnerText.Trim()!="")
strMarctxt=Server.HtmlEncode(ObjMarcTxtNode.InnerText);
}
if (strMarctxt !="")
{
string tmpspace = "\n" + " ";
strMarctxt= strMarctxt.Replace(tmpspace, " ");
string strControlNo = ObjHoldings.ParseXML("008 |", strMarctxt).ToString();
if (strControlNo.Trim()!="")
strRecLanguage= strControlNo.Substring(35,3);
string strNativeDelimiter = " ";
//Native Identifier
//ISBN
string strNativeISBN = ObjHoldings.Parse880XML("|020-",strMarctxt).ToString();
//'ISSN
string strNativeISSN = ObjHoldings.Parse880XML("|022-",strMarctxt).ToString();
if (strNativeISBN.Trim()!="" || strNativeISSN.Trim()!="")
{
strNativeIdentifier = (strNativeISBN.Trim().Length>0?strNativeISBN + strNativeDelimiter:"") + strNativeISSN.Trim();
strNativeIdentifier = strNativeIdentifier.Replace("|","");
}
pls advice how i can pass the xml file instead of the url and get info or tag 020 and 022 from the xml file.
we have tag 020 and 022 in the xml file.pls advice
|
|
|
|