how to escape xml space in service? - html

hi now i m working with XSLT and now i call to a service
as like this
<xsl:for-each select="ext">
<config type="2" liveserver="XXX.com" localserver="XXX.com" httpuri="/myservices/jsonrequesthomenew?companyid=homepage&outputtype=xml" params="" readtimeout="10000"/>
</xsl:for-each>
if i cehck to this live url than show to this result
<?xml version="1.0" encoding="UTF-8"?>
<indexes>
<data>
<sensex>
<CloseIndexValue>25719.58</CloseIndexValue>
<trend>equal</trend>
<premarket>false</premarket>
<DateTime>03:53 PM | 10 Sep 2015</DateTime>
<CurrentIndexValue>25622.17</CurrentIndexValue>
<Segment>BSE</Segment>
<OpenIndexValue>25522.96</OpenIndexValue>
<IndexName>SENSEX</IndexName>
<PercentChange>-0.38</PercentChange>
<NetChange>-97.41</NetChange>
</sensex>
<nifty>
<CloseIndexValue>7818.60</CloseIndexValue>
<trend>equal</trend>
<premarket>false</premarket>
<DateTime>03:53 PM | 10 Sep 2015</DateTime>
<CurrentIndexValue>7788.10</CurrentIndexValue>
<Segment>NSE</Segment>
<OpenIndexValue>7729.05</OpenIndexValue>
<IndexName>CNX NIFTY</IndexName>
<PercentChange>-0.39</PercentChange>
<NetChange>-30.50</NetChange>
</nifty>
<USD>
<DateTime>2015-09-10 15:48:06.0</DateTime>
<netChange>0.05</netChange>
<percentChange>0.08</percentChange>
<name>USD/INR</name>
<bidprice>66.47</bidprice>
</USD>
<silver>
<ClosePrice>35294.00</ClosePrice>
<trend>negative</trend>
<OpenPrice>35391.00</OpenPrice>
<ExpiryDate>2015-12-04</ExpiryDate>
<SpotSymbol>SSILVERAHM</SpotSymbol>
<LastTradedPrice>35475.00</LastTradedPrice>
<DateTime>10-September-2015 15:46:32</DateTime>
<Symbol>SILVER</Symbol>
<PercentChange>0.51</PercentChange>
<CommodityName>Silver</CommodityName>
<NetChange>181.00</NetChange>
<SpotPrice>34912.0</SpotPrice>
<PriceQuotationUnit>1 KGS </PriceQuotationUnit>
</silver>
<marketstatus>
<currentMarketStatus>Live</currentMarketStatus>
</marketstatus>
<gold>
<ClosePrice>26057.00</ClosePrice>
<trend>positive</trend>
<OpenPrice>26143.00</OpenPrice>
<ExpiryDate>2015-10-05</ExpiryDate>
<SpotSymbol>SGOLDAHM</SpotSymbol>
<LastTradedPrice>26067.00</LastTradedPrice>
<DateTime>10-September-2015 15:46:15</DateTime>
<Symbol>GOLD</Symbol>
<PercentChange>0.04</PercentChange>
<CommodityName>Gold</CommodityName>
<NetChange>10.00</NetChange>
<SpotPrice>26003.0</SpotPrice>
<PriceQuotationUnit>10 GRMS </PriceQuotationUnit>
</gold>
<DXY Index>
<DateTime>2015-09-10 15:49:21.0</DateTime>
<netChange>0.1</netChange>
<percentChange>0.1</percentChange>
<name>DXY Index</name>
<bidprice>96.11</bidprice>
</DXY Index>
</data>
</indexes>
but this service is not call to my xslt file why can u please help me .
i check to this xml data validate in thsi url http://www.xmlvalidation.com/index.php?id=1&L=0
than show to this error
Click on to jump to the error. In the document, you can point at with your mouse to see the error message.
Errors in the XML document:
1: 1931 Attribute name "Index" associated with an element type "DXY" must be followed by the ' = ' character.
How to resolve this error in front end .

The error you are getting is because of this element in your XML
<DXY Index>
<DateTime>2015-09-10 15:49:21.0</DateTime>
<netChange>0.1</netChange>
<percentChange>0.1</percentChange>
<name>DXY Index</name>
<bidprice>96.11</bidprice>
</DXY Index>
DXY Index is not a valid element name, as you can't have spaces in element names.
The XML needs to be corrected, so the name is something DXYIndex or DXY-Index, although the name you actually use will depend on what the XML is actually used for.

Related

Formatting issue in XML with the elements with the same name at different levels

I'm getting the following format for my XML data:
<?xml version="1.0" encoding="UTF-8"?>
<n0:MT_NODE_CodingList xmlns:n0="cdcvvrvrv">
<DocumentId>78D6590F-2843-434D-AF0F-76B11680B6AD</DocumentId>
<CodingLines> <CurrentDocumentLineReferenceId>00001</CurrentDocumentLineReferenceId>
<LineID>00001</LineID>
<UUID>3CA6E835-1F8F-4B7F-A255-FCBF766AE1C8</UUID>
<Amount>7000000.00</Amount>
<currencyID>USD</currencyID>
<Quantity>100000.000</Quantity>
<unitCode>KGM</unitCode>
<Codes> <ID>purchasinggroup</ID>
<Name>Reserve for Source</Name>
<Value>530</Value>
</Codes> </CodingLines> </n0:MT_NODE_CodingList>
I would like to convert the XML to the format below:
{"DocumentId":"41DCF8A4-6D05-4A8F-9265-F5E6BCD96CCF",
"CodingLines":{{"CodingLines":[{"ID":{"value":"177AFD35-5EF5-4466-88C6-B4755CC2E1A0"},
"OrderLineReference":[{"LineID":{"value":"00001"}}],
"CurrentDocumentLineReferenceId":"00001",
"Amount":{"value":"100.00 ",
"currencyID":"USD"},
"Quantity":{"value":"100.000 ",
"unitCode":"GIA"},"Codes":[{"ID":{"value":"purchasinggroup"},
"Name":{"value":"Reserve for Source"},
"Value":{"value":108}}]}]}}}
But when I do the conversion from the SAP Application I am getting XML with the format below:
{"DocumentId":"41DCF8A4-6D05-4A8F-9265-F5E6BCD96CCF",
"CodingLines":[{"CodingLines":[{"ID":{"value":"177AFD35-5EF5-4466-88C6-B4755CC2E1A0"},
"OrderLineReference":[{"LineID":{"value":"00001"}}],
"CurrentDocumentLineReferenceId":"00001",
"Amount":{"value":"100.00 ",
"currencyID":"USD"},
"Quantity":{"value":"100.000 ",
"unitCode":"GIA"},
"Codes":[{"ID":{"value":"purchasinggroup"},
"Name":{"value":"Reserve for Source"},
"Value":{"value":108}}]}]}]}
What do I have to do to make the first CodingLines start with '{' and the CodingLines in the level below to have an array '['.

xpath filter - how to filter to the latest node record

I have an issue with filtering xpath on specified node to have only the latest record. In the example xml there s a rule that the very first record on each node is the most current information. I would like to filter all records which are not relevant (different than the first record).
The second rule is that i do not want to use date conditions to filter all job_information records after the very first one.
Normally I am using xpath tester with expression such like:
/queryCompoundEmployeeResponse/CompoundEmployee[(person/employment_information/job_information[1])]
which gives me only the first record of job information but here is does not work. Can you show me what is wrong with it?
Can you help me?
xml input with 3 job_information records
<queryCompoundEmployeeResponse>
<CompoundEmployee>
<id>11111</id>
<person>
<employment_information>
<job_information>
<end_date>9999-12-31</end_date>
<start_date>2017-05-17</start_date>
</job_information>
<job_information>
<end_date>2018-12-31</end_date>
<start_date>2017-05-17</start_date>
</job_information>
<job_information>
<end_date>2016-12-31</end_date>
<start_date>2013-05-17</start_date>
</job_information>
</employment_information>
</person>
</CompoundEmployee>
</queryCompoundEmployeeResponse>
xml output I would like to have
<queryCompoundEmployeeResponse>
<CompoundEmployee>
<id>11111</id>
<person>
<employment_information>
<job_information>
<end_date>9999-12-31</end_date>
<start_date>2017-05-17</start_date>
</job_information>
</employment_information>
</person>
</CompoundEmployee>
</queryCompoundEmployeeResponse>
Assuming you have always the same XML structure, you can try :
data=xmlParse("C:/Users/.../pathtoyourxmlfile.xml")
a=xpathSApply(data,"count(//job_information[1]/ancestor::*)+6")
b=xpathSApply(data,"count(//job_information)-1")*4+(a-1)
old=read_lines("C:/Users/.../pathtoyourxmlfile.xml")
new = old[-(a:b)]
writeLines(new,con = "new.xml")
Output (new.xml) :
<queryCompoundEmployeeResponse>
<CompoundEmployee>
<id>11111</id>
<person>
<employment_information>
<job_information>
<end_date>9999-12-31</end_date>
<start_date>2017-05-17</start_date>
</job_information>
</employment_information>
</person>
</CompoundEmployee>
</queryCompoundEmployeeResponse>

Quickbooks message: "Object "..." specified in the request cannot be found"

I'm the programmer for a company that sells a web-based business software product, that lets the user run their business. Our system is also required to sync all financial information to our user's Desktop QuickBoooks. We use the QB Web Connector to do this.
When I send an invoice to QB that has already been paid in our system, first I send an InvoiceAddRq. I specify the exact AR account name in the ARAccountRef field.
When the InvoiceAddRs comes back, if the statusSeverity is INFO and the statusMessage is "Status OK", then I read the TxnID from the XML and store in in our database.
Then when the web connector sends the request for the next operation, I read the same TxnID from the database and send a ReceivePaymentAddRq, in which I use the exact same AR account name in the ARAccountRef, the exact same customer name in the CustomerRef, and in the AppliedToTxnAdd block of the ReceivePaymentAddRq, I use that same TxnID from the InvoiceAddRs for TxnID and the same invoice total for PaymentAmount that I sent in the InvoiceAddRq's InvoiceLineAdd's Amount field.
(Our InvoiceAddRq's always contain only one Invoice Line, with the grand total of the invoice in our system. We don't import our customers' individual items.)
Now -- Sometimes this works fine, but sometimes the ReceivePaymentAddRs contains the error "Object "..." specified in the request cannot be found" -- where the "..." is the TxnID I got from the initial InvoiceAddRs.
When this happens, the customer verifies to us that the respective invoice is indeed in their QB, but is not marked paid.
Also, to NOTE, our customers are NOT using multiple currencies, all currencies are in USD$, and the ReceivePaymentAddRq happens within a couple seconds after the InvoiceAddRq, which means that no QB user in the customer's company has time to modify the newly inserted invoice.
Why does this happen? Is it a QB bug?
EDIT:
2017-01-04 14:24:21
<?xml version="1.0" encoding="utf-8"?>
<?qbxml version="8.0"?>
<QBXML>
<QBXMLMsgsRq onError="stopOnError">
<InvoiceAddRq>
<InvoiceAdd>
<CustomerRef>
<FullName>SILMAN DC</FullName>
</CustomerRef>
<ARAccountRef>
<FullName>Accounts Receivable:Accounts Receivable</FullName>
</ARAccountRef>
<TxnDate>2017-01-04</TxnDate>
<RefNumber>77671</RefNumber>
<BillAddress>
<Addr1>SILMAN DC</Addr1>
<Addr2>1053 31ST STREET NW</Addr2>
<Addr3/>
<Addr4/>
<City>WASHINGTON</City>
<State>DC</State>
<PostalCode>20007</PostalCode>
</BillAddress>
<ShipAddress>
<Addr1>1053 31ST STREET NW</Addr1>
<Addr2/>
<Addr3/>
<City>WASHINGTON</City>
<State>DC</State>
<PostalCode>20007</PostalCode>
</ShipAddress>
<PONumber/>
<TermsRef>
<FullName>Credit Card</FullName>
</TermsRef>
<InvoiceLineAdd>
<ItemRef>
<FullName>Invoice</FullName>
</ItemRef>
<Desc>Invoice</Desc>
<Quantity>1</Quantity>
<Amount>59.21</Amount>
</InvoiceLineAdd>
</InvoiceAdd>
</InvoiceAddRq>
</QBXMLMsgsRq>
</QBXML>
2017-01-04 14:24:21
<?xml version="1.0"?>
<QBXML>
<QBXMLMsgsRs>
<InvoiceAddRs statusCode="0" statusSeverity="Info" statusMessage="Status OK">
<InvoiceRet>
<TxnID>A13F8-1483561159</TxnID>
<TimeCreated>2017-01-04T15:19:19-05:00</TimeCreated>
<TimeModified>2017-01-04T15:19:19-05:00</TimeModified>
<EditSequence>1483561159</EditSequence>
<TxnNumber>133184</TxnNumber>
<CustomerRef>
<ListID>800005FF-1478123373</ListID>
<FullName>SILMAN DC</FullName>
</CustomerRef>
<ARAccountRef>
<ListID>80000025-1423671174</ListID>
<FullName>Accounts Receivable:Accounts Receivable</FullName>
</ARAccountRef>
<TemplateRef>
<ListID>80000003-1423576739</ListID>
<FullName>Intuit Service Invoice</FullName>
</TemplateRef>
<TxnDate>2017-01-04</TxnDate>
<RefNumber>77671</RefNumber>
<BillAddress>
<Addr1>SILMAN DC</Addr1>
<Addr2>1053 31ST STREET NW</Addr2>
<City>WASHINGTON</City>
<State>DC</State>
<PostalCode>20007</PostalCode>
</BillAddress>
<BillAddressBlock>
<Addr1>SILMAN DC</Addr1>
<Addr2>1053 31ST STREET NW</Addr2>
<Addr3>WASHINGTON, DC 20007</Addr3>
</BillAddressBlock>
<ShipAddress>
<Addr1>1053 31ST STREET NW</Addr1>
<City>WASHINGTON</City>
<State>DC</State>
<PostalCode>20007</PostalCode>
</ShipAddress>
<ShipAddressBlock>
<Addr1>1053 31ST STREET NW</Addr1>
<Addr2>WASHINGTON, DC 20007</Addr2>
</ShipAddressBlock>
<IsPending>false</IsPending>
<IsFinanceCharge>false</IsFinanceCharge>
<TermsRef>
<ListID>80000009-1425488517</ListID>
<FullName>Credit Card</FullName>
</TermsRef>
<DueDate>2017-01-04</DueDate>
<ShipDate>2017-01-04</ShipDate>
<Subtotal>59.21</Subtotal>
<SalesTaxPercentage>0.00</SalesTaxPercentage>
<SalesTaxTotal>0.00</SalesTaxTotal>
<AppliedAmount>0.00</AppliedAmount>
<BalanceRemaining>59.21</BalanceRemaining>
<IsPaid>false</IsPaid>
<IsToBePrinted>true</IsToBePrinted>
<IsToBeEmailed>false</IsToBeEmailed>
<InvoiceLineRet>
<TxnLineID>A13FA-1483561159</TxnLineID>
<ItemRef>
<ListID>80000003-1423676477</ListID>
<FullName>Invoice</FullName>
</ItemRef>
<Desc>Invoice</Desc>
<Quantity>1</Quantity>
<Rate>59.21</Rate>
<Amount>59.21</Amount>
<SalesTaxCodeRef>
<ListID>80000002-1423576739</ListID>
<FullName>Non</FullName>
</SalesTaxCodeRef>
</InvoiceLineRet>
</InvoiceRet>
</InvoiceAddRs>
</QBXMLMsgsRs>
</QBXML>
2017-01-04 14:25:33
<?xml version="1.0" encoding="utf-8"?>
<?qbxml version="8.0"?>
<QBXML>
<QBXMLMsgsRq onError="stopOnError">
<ReceivePaymentAddRq>
<ReceivePaymentAdd>
<CustomerRef>
<FullName>SILMAN DC</FullName>
</CustomerRef>
<TotalAmount>59.21</TotalAmount>
<PaymentMethodRef>
<FullName>Credit Card</FullName>
</PaymentMethodRef>
<DepositToAccountRef>
<FullName>Undeposited Funds</FullName>
</DepositToAccountRef>
<AppliedToTxnAdd>
<TxnID>A13F8-1483561159</TxnID>
<PaymentAmount>59.21</PaymentAmount>
</AppliedToTxnAdd>
</ReceivePaymentAdd>
</ReceivePaymentAddRq>
</QBXMLMsgsRq>
</QBXML>
2017-01-04 14:25:33
<?xml version="1.0"?>
<QBXML>
<QBXMLMsgsRs>
<ReceivePaymentAddRs statusCode="3120" statusSeverity="Error" statusMessage="Object "A13F8-1483561159" specified in the request cannot be found. "/>
</QBXMLMsgsRs>
</QBXML>
OK, one correction: It seems that I am NOT including an ARAccountRef aggregate in my ReceivePaymentAddRq. Probably because the IDN Unified OSR said it was optional. Is this the problem? Remember, it only happens once in a while...
**EDIT:
I added the ARAccountRef aggregate in my ReceivePaymentAddRq. Still getting the error.

Convert from HTML::Template to PDF:FromHtml says invalid XML

I create an HTML file using HTML::Template. The resulting code is a valid XML/HTML (check against a xml validator). But while convert to pdf using PDF::FromHTML a message of "invalid token in xml file" is found.
Trying changing the first declaration line from doctype to xml, or supressing, but nothing works. XML::Simple, PDF:API2, XML::Writer are last version.
Ay idea what is happening?
# create template object and store to verify
shout('s',"create template from $str_filepath") if ($bool_DEBUG);
$str_mytemplate = HTML::Template->new(filename => $str_filepath, case_sensitive => 0, no_includes => 1 );
$str_mytemplate->param(\%strct_toreplace);
$str_filepath = envDir('temp').newID().'.html';
shout('',"template created, storing to : $str_filepath") if ($bool_DEBUG);
if (open(FILE, '>', $str_filepath)) {
print FILE $str_mytemplate->output;
close (FILE);
}
# generate pdf from created file
shout('p',"Creating PDF ") if ($bool_DEBUG);
$pdf_this = PDF::FromHTML->new( encoding => 'utf-8' );
$pdf_this->load_file($str_filepath);
$pdf_this->convert( LineHeight => 10, Landscape => 1, PageSize => 'Letter', );
shout('p',"Display PDF") if ($bool_DEBUG);
print header(-type=>'application/pdf', -charset=>'UTF-8');
print $pdf_this->write_file();
$bool_DEBUG and shout(); are a variable and procedure to set and display messages while debugging mode.
Html code generated via template: http://www.etoxica.com/examplecode.html
Template used: http://www.etoxica.com/exampletemplate.tmpl
Message displayed:
SECTION: Creating PDF
Software error:
not well-formed (invalid token) at line 19, column 13, byte 430 at /usr/local/lib64/perl5/XML/Parser.pm line 187.
at /home/grupo/perl/usr/share/perl5/PDF/FromHTML.pm line 141.
Summary: Found the problem (I guess) ;)
Consider the following lines:
<td>
Some line of data
<br/>
A second line of data
</td>
When try to be read by PDF::FromHTML it will send a message of malformed token in the 5th line, specifically on the slash '/' from </td> tag; BUT, that is not the problem, the problem is created by the <br/> tag inside the <td></td>.
If it is changed to <br> or <br /> no error is found. I don't know if using <br> is a good html practice to xml compability, even is defined as it w3c br semantic.

SelectNodes and GetElementsByTagName

what are main differences between SelectNodes and GetElementsByTagName.
SelectNodes is a .NET/MSXML-specific method that gets a list of matching nodes for an XPath expression. XPaths can select elements by tag name but can also do lots of other, more complicated selection rules.
getElementByTagName is a DOM Level 1 Core standard method available in many languages (but spelled with a capital G in .NET). It selects elements only by tag name; you can't ask it to select elements with a certain attribute, or elements with tag name a inside other elements with tag name b or anything clever like that. It's older, simpler, and in some environments faster.
SelectNodes takes an XPath expression as a parameter and returns all nodes that match that expression.
GetElementsByTagName takes a tag name as a parameter and returns all tags that have that name.
SelectNodes is therefore more expressive, as you can write any GetElementsByTagName call as a SelectNodes call, but not the other way around. XPath is a very robust way of expressing sets of XML nodes, offering more ways of filtering than just name. XPath, for example, can filter by tag name, attribute names, inner content and various aggregate functions on tag children as well.
SelectNodes() is a Microsoft extension to the Document Object Model (DOM) (msdn).
SelectNodes as mentioned by Welbog and others takes XPath expression. I would like to mention difference with GetElementsByTagName() when deleting xml node is needed.
Answer and code provided user chilberto at msdn forum
The next test illustrates the difference by performing the same function (removing the person nodes) but by using the GetElementByTagName() method to select the nodes. Though the same object type is returned its construction is different. The SelectNodes() is a collection of references back to the xml document. That means we can remove from the document in a foreach without affecting the list of references. This is shown by the count of the nodelist not being affected. The GetElementByTagName() is a collection that directly reflects the nodes in the document. That means as we remove the items in the parent, we actually affect the collection of nodes. This is why the nodelist can not be manipulated in a foreach but had to be changed to a while loop.
.NET SelectNodes()
[TestMethod]
public void TestSelectNodesBehavior()
{
XmlDocument doc = new XmlDocument();
doc.LoadXml(#"<root>
<person>
<id>1</id>
<name>j</name>
</person>
<person>
<id>2</id>
<name>j</name>
</person>
<person>
<id>1</id>
<name>j</name>
</person>
<person>
<id>3</id>
<name>j</name>
</person>
<business></business>
</root>");
XmlNodeList nodeList = doc.SelectNodes("/root/person");
Assert.AreEqual(5, doc.FirstChild.ChildNodes.Count, "There should have been a total of 5 nodes: 4 person nodes and 1 business node");
Assert.AreEqual(4, nodeList.Count, "There should have been a total of 4 nodes");
foreach (XmlNode n in nodeList)
n.ParentNode.RemoveChild(n);
Assert.AreEqual(1, doc.FirstChild.ChildNodes.Count, "There should have been only 1 business node left in the document");
Assert.AreEqual(4, nodeList.Count, "There should have been a total of 4 nodes");
}
.NET GetElementsByTagName()
[TestMethod]
public void TestGetElementsByTagNameBehavior()
{
XmlDocument doc = new XmlDocument();
doc.LoadXml(#"<root>
<person>
<id>1</id>
<name>j</name>
</person>
<person>
<id>2</id>
<name>j</name>
</person>
<person>
<id>1</id>
<name>j</name>
</person>
<person>
<id>3</id>
<name>j</name>
</person>
<business></business>
</root>");;
XmlNodeList nodeList = doc.GetElementsByTagName("person");
Assert.AreEqual(5, doc.FirstChild.ChildNodes.Count, "There should have been a total of 5 nodes: 4 person nodes and 1 business node");
Assert.AreEqual(4, nodeList.Count, "There should have been a total of 4 nodes");
while (nodeList.Count > 0)
nodeList[0].ParentNode.RemoveChild(nodeList[0]);
Assert.AreEqual(1, doc.FirstChild.ChildNodes.Count, "There should have been only 1 business node left in the document");
Assert.AreEqual(0, nodeList.Count, "All the nodes have been removed");
}
With SelectNodes() we get collection / list of references to xml document nodes. We can manipulate with those references. If we delete node, the change will be visible to xml document, but the collection / list of references is the same (although node which was deleted, it's reference points now to null -> System.NullReferenceException) Although I do not really know how this is implemented. I suppose if we use XmlNodeList nodeList = GetElementsByTagName() and delete node with nodeList[i].ParentNode.RemoveChild(nodeList[i]) is frees/deletes reference in nodeList variable.