Quantcast
Channel: XML, System.Xml, MSXML and XmlLite forum
Viewing all 935 articles
Browse latest View live

How to combine 2 XMl nodes from the same document when they have child node with same value

$
0
0


-<NewDataSet>


-<Header>

<BankName>SAMA</BankName>

<CashCenterName>SAMA Riyadh</CashCenterName>

</Header>


-<DepositorList>

<ReferenceNumber>1</ReferenceNumber>

<DepositList_Id>0</DepositList_Id>

<PreparedBy>FZE</PreparedBy>

<TotalContainerCount>2</TotalContainerCount>

<ExpectedDate>2018-04-19T09:13:10-05:00</ExpectedDate>

<DeclaredAmount>150000</DeclaredAmount>

</DepositorList>


-<DepositorList>

<ReferenceNumber>1</ReferenceNumber>

<DepositList_Id>1</DepositList_Id>

<PreparedBy>FZE</PreparedBy>

<TotalContainerCount>2</TotalContainerCount>

<ExpectedDate>2018-04-19T09:13:10-05:00</ExpectedDate>

<DeclaredAmount>500000</DeclaredAmount>

</DepositorList>


-<DepositorList>

<ReferenceNumber>1</ReferenceNumber>

<DepositList_Id>2</DepositList_Id>

<PreparedBy>FZE</PreparedBy>

<TotalContainerCount>2</TotalContainerCount>

<ExpectedDate>2018-04-19T09:13:10-05:00</ExpectedDate>

<DeclaredAmount>2100000</DeclaredAmount>

</DepositorList>


-<DepositorList>

<ReferenceNumber>1</ReferenceNumber>

<DepositList_Id>3</DepositList_Id>

<PreparedBy>FZE</PreparedBy>

<TotalContainerCount>2</TotalContainerCount>

<ExpectedDate>2018-04-19T09:13:10-05:00</ExpectedDate>

<DeclaredAmount>1100000</DeclaredAmount>

</DepositorList>


-<DepositorList>

<ReferenceNumber>1</ReferenceNumber>

<DepositList_Id>4</DepositList_Id>

<PreparedBy>FZE</PreparedBy>

<TotalContainerCount>2</TotalContainerCount>

<ExpectedDate>2018-04-19T09:13:10-05:00</ExpectedDate>

<DeclaredAmount>1200000</DeclaredAmount>

</DepositorList>


-<Carrier>

<CarrierName>tns1:Commercial CIT</CarrierName>

<CarrierNumber>10001</CarrierNumber>

<CarrierLocationName>tns1:Riyadh</CarrierLocationName>

<CarrierLocationNumber>100011</CarrierLocationNumber>

<CarrierLocationRouteName>tns1:R1</CarrierLocationRouteName>

<CarrierLocationRouteNumber>R1</CarrierLocationRouteNumber>

<DepositList_Id>0</DepositList_Id>

</Carrier>


-<Carrier>

<CarrierName>tns1:Commercial CIT</CarrierName>

<CarrierNumber>10001</CarrierNumber>

<CarrierLocationName>tns1:Riyadh</CarrierLocationName>

<CarrierLocationNumber>100011</CarrierLocationNumber>

<CarrierLocationRouteName>tns1:R1</CarrierLocationRouteName>

<CarrierLocationRouteNumber>R1</CarrierLocationRouteNumber>

<DepositList_Id>1</DepositList_Id>

</Carrier>


-<Carrier>

<CarrierName>tns1:Commercial CIT</CarrierName>

<CarrierNumber>10001</CarrierNumber>

<CarrierLocationName>tns1:Riyadh</CarrierLocationName>

<CarrierLocationNumber>100011</CarrierLocationNumber>

<CarrierLocationRouteName>tns1:R1</CarrierLocationRouteName>

<CarrierLocationRouteNumber>R1</CarrierLocationRouteNumber>

<DepositList_Id>2</DepositList_Id>

</Carrier>


-<Carrier>

<CarrierName>tns1:Commercial CIT</CarrierName>

<CarrierNumber>10001</CarrierNumber>

<CarrierLocationName>tns1:Riyadh</CarrierLocationName>

<CarrierLocationNumber>100011</CarrierLocationNumber>

<CarrierLocationRouteName>tns1:R1</CarrierLocationRouteName>

<CarrierLocationRouteNumber>R1</CarrierLocationRouteNumber>

<DepositList_Id>3</DepositList_Id>

</Carrier>


-<Carrier>

<CarrierName>tns1:Commercial CIT</CarrierName>

<CarrierNumber>10001</CarrierNumber>

<CarrierLocationName>tns1:Riyadh</CarrierLocationName>

<CarrierLocationNumber>100011</CarrierLocationNumber>

<CarrierLocationRouteName>tns1:R1</CarrierLocationRouteName>

<CarrierLocationRouteNumber>R1</CarrierLocationRouteNumber>

<DepositList_Id>4</DepositList_Id>

</Carrier>

</NewDataSet>

Here I want to combine DepositorList node with Carrier Node as you can see they have DepositList_Id as a common child

The output I am expecting is


-<tns:Header>


<tns1:BankName>SAMA</tns1:BankName>

<tns1:CashCenterName>SAMA Riyadh</tns1:CashCenterName>

</tns:Header>


-<tns:DepositList>

<tns1:ReferenceNumber>00000001</tns1:ReferenceNumber>


-<tns1:Carrier>

<tns1:CarrierName>tns1:Commercial CIT</tns1:CarrierName>

<tns1:CarrierNumber>10001</tns1:CarrierNumber>

<tns1:CarrierLocationName>tns1:Riyadh</tns1:CarrierLocationName>

<tns1:CarrierLocationNumber>100011</tns1:CarrierLocationNumber>

<tns1:CarrierLocationRouteName>tns1:R1</tns1:CarrierLocationRouteName>

<tns1:CarrierLocationRouteNumber>R1</tns1:CarrierLocationRouteNumber>

</tns1:Carrier>

<tns1:PreparedBy>FZE</tns1:PreparedBy>

<tns1:TotalContainerCount>2</tns1:TotalContainerCount>

<tns1:ExpectedDate>2018-04-19T09:13:10-05:00</tns1:ExpectedDate>

<tns1:DeclaredAmount>150000.00</tns1:DeclaredAmount>

</tns:DepositList>

......Likewise for others

I have not worked much with XMl in C#, getting confused a lot tried merge but it just merges it down to the existing node and changes the node name as well .. Please suggest


How Do I Remove a Namespace from an XElement?

$
0
0

Dim root as XElement =

   <Root xmlns="http://services.pivot.rrd.com/US01_PVT9019WS/">
        <Child1>1</Child1>
        <Child2>2</Child2>
        <Child3>3</Child3>
    </Root>

How do I remove the namespace?


John Bailo RR Donnelley

Heap corruption during schema validation with MSXML6

$
0
0

I believe that I've discovered a validation scenario that causes a Heap corruption in MSXML6.

I've been using the MSXML6 ISAXXMLReader to validate xml against an xsd schema in my application. The scenario that causes the issue is when you have multiple references to an IDREF that is not found in the xml document. Curiously only having one reference does not cause the issue. For example with the following schema:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning" elementFormDefault="qualified" attributeFormDefault="unqualified" vc:minVersion="1.1"><xs:element name="Example"><xs:annotation><xs:documentation>Comment describing your root element</xs:documentation></xs:annotation><xs:complexType><xs:sequence><xs:element name="ExampleElement" type="xs:IDREF" minOccurs="0" maxOccurs="unbounded"/><xs:element name="IDElement" type="xs:ID" minOccurs="0"/></xs:sequence></xs:complexType></xs:element></xs:schema>


This xml example returns the expected validation message:

    example_good.xml

<Example><ExampleElement>ID1</ExampleElement></Example>


output:

    Parsing document: example_good.xml

    Error Message:
    The ID 'ID1' is referenced but not defined in the document.

    Error Message:
    Validate failed.

    Parse result code: c00ce225

However, if you have two referenced ID's that are not found the SAX reader will return the following error message:

    example_bad.xml

<Example><ExampleElement>ID1</ExampleElement><ExampleElement>ID1</ExampleElement></Example>

output:

    Parsing document: example_bad.xml

    Error Message:
    System error: -1072898003.

    Error Message:
    Validate failed.

    Parse result code: c00ce225

In addition to that, later in my program's execution (in an entirely different dll) when stopping the thread the whole application would crash with heap corruption error.

To isolate what was causing the issue I made a simple cli version of the SAX validator. My implementation is very similar to the [example on msdn.](https://msdn.microsoft.com/en-us/library/cc507429(v=vs.85).aspx) 

#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif

#include <stdio.h>
#include <tchar.h>
#include <windows.h>
#include <objbase.h>

#if _WIN32 
#import <msxml6.dll> no_auto_exclude
#else
#import <msxml6.dll>
#endif

#include "SAXErrorHandlerImpl.h"

int _tmain(int argc, _TCHAR* argv[])
{
	if (argc<2) {
		printf("\nTo run, enter\n\tSaxJumpStart file:///drive:/path/file.xml\n\n");
		return 0;	// Need URL to read
	}

	CoInitialize(NULL);
	ISAXXMLReader* pRdr = NULL;

	HRESULT hr = CoCreateInstance(
		__uuidof(SAXXMLReader60),
		NULL,
		CLSCTX_ALL,
		__uuidof(ISAXXMLReader),
		(void **)&pRdr);

	if (!FAILED(hr))
	{
		// Set IATA namespace for NDC transactions and path to schema file
		_bstr_t bstrNamespace = L"";
		_bstr_t bstrPath = "Example.xsd";

		// Configure Schema Cache
		MSXML2::IXMLDOMSchemaCollectionPtr pXS;
		pXS.CreateInstance(__uuidof(XMLSchemaCache60), NULL, CLSCTX_INPROC_SERVER);
		pXS->add(bstrNamespace, bstrPath);

		// Configure SAX Reader for schema validation
		hr = pRdr->putFeature(L"schema-validation", VARIANT_TRUE);
		hr = pRdr->putFeature(L"exhaustive-errors", VARIANT_TRUE);	// Show just one or all errors
		hr = pRdr->putProperty(L"schemas", _variant_t(pXS.GetInterfacePtr()));

		// Set error handler
		SAXErrorHandlerImpl * pEc = new SAXErrorHandlerImpl();
		hr = pRdr->putErrorHandler(pEc);

		printf("\nParsing document: %S\n", argv[1]);

		hr = pRdr->parseURL(argv[1]);
		printf("\nParse result code: %08x\n\n", hr);

		pRdr->Release();
	}
	else
	{
		printf("\nError %08X\n\n", hr);
	}

	CoUninitialize();
	return 0;
}

When I run this using the Application Verifier it crashes on the pRdr->parseURL() function. This is the output of the Application Verirfier:

<avrf:logfile xmlns:avrf="Application Verifier"><avrf:logSession TimeStarted="2018-05-11 : 16:18:34" PID="29252" Version="2"><avrf:logEntry Time="2018-05-11 : 16:18:35" LayerName="Heaps" StopCode="0x13" Severity="Error"><avrf:message>First chance access violation for current stack trace.</avrf:message><avrf:parameter1>d25afc8 - Invalid address causing the exception.</avrf:parameter1><avrf:parameter2>fc63f35 - Code address executing the invalid access.</avrf:parameter2><avrf:parameter3>9bf4e8 - Exception record.</avrf:parameter3><avrf:parameter4>9bf538 - Context record.</avrf:parameter4><avrf:stackTrace><avrf:trace>vrfcore!VerifierDisableVerifier+708 ( @ 0)</avrf:trace><avrf:trace>verifier!VerifierStopMessage+74 ( @ 0)</avrf:trace><avrf:trace>ntdll!RtlApplicationVerifierStop+7d ( @ 0)</avrf:trace><avrf:trace>vfbasics!+fa57160 ( @ 0)</avrf:trace><avrf:trace>vfbasics!+fa587e8 ( @ 0)</avrf:trace><avrf:trace>vfbasics!+fa58134 ( @ 0)</avrf:trace><avrf:trace>ntdll!WinSqmEventWrite+1d1ee ( @ 0)</avrf:trace><avrf:trace>ntdll!RtlUnwind+1ba ( @ 0)</avrf:trace><avrf:trace>ntdll!KiUserExceptionDispatcher+f ( @ 0)</avrf:trace><avrf:trace>msxml6!StartUI+5e0a2 ( @ 0)</avrf:trace><avrf:trace>msxml6!StartUI+3c6a5 ( @ 0)</avrf:trace><avrf:trace>msxml6!StartUI+89e4a ( @ 0)</avrf:trace><avrf:trace>msxml6!StartUI+8a707 ( @ 0)</avrf:trace><avrf:trace>msxml6!StartUI+8b76e ( @ 0)</avrf:trace><avrf:trace>msxml6!StartUI+9f12a ( @ 0)</avrf:trace><avrf:trace>SAXErrorHandling!wmain+2ff (c:\users\rmelrose\documents\visual studio 2015\projects\schemalocationproj\schemalocationproj\saxval.cpp @ 57)</avrf:trace><avrf:trace>SAXErrorHandling!invoke_main+1e (f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl @ 79)</avrf:trace><avrf:trace>SAXErrorHandling!__scrt_common_main_seh+150 (f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl @ 253)</avrf:trace><avrf:trace>SAXErrorHandling!__scrt_common_main+d (f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl @ 296)</avrf:trace><avrf:trace>SAXErrorHandling!wmainCRTStartup+8 (f:\dd\vctools\crt\vcstartup\src\startup\exe_wmain.cpp @ 17)</avrf:trace><avrf:trace>KERNEL32!BaseThreadInitThunk+24 ( @ 0)</avrf:trace><avrf:trace>ntdll!RtlSubscribeWnfStateChangeNotification+439 ( @ 0)</avrf:trace><avrf:trace>ntdll!RtlSubscribeWnfStateChangeNotification+404 ( @ 0)</avrf:trace></avrf:stackTrace></avrf:logEntry></avrf:logSession></avrf:logfile>

Is this an issue with MSXML6 or the way that I am using it? 

Is there anything I can do to keep it from crashing my application?

    

Xsd Schema

$
0
0
Good Morning,
Can anyone give me the xsd file Sepa C2B Version 03.00 from 2016-11-21 with the tag NbOfTxsPerSts inside the OrgnlPmtInfAndSts tag.
Any help would be appreciated,
Iber Costa

Modify XSLT file according to output xml

$
0
0

I would like to modify my existing xslt file to get the xml in the output form

Input XML is:

 

 -<NewDataSet>


 -<Header>

<BankName>SAMA</BankName>

<CashCenterName>SAMA Riyadh</CashCenterName>

</Header>


 -<DepositorList>

<ReferenceNumber>1</ReferenceNumber>

<DepositList_Id>0</DepositList_Id>

<PreparedBy>FZE</PreparedBy>

<TotalContainerCount>2</TotalContainerCount>

<ExpectedDate>2018-04-19T09:13:10-05:00</ExpectedDate>

<DeclaredAmount>150000</DeclaredAmount>

</DepositorList>

-<Carrier>

<CarrierName>tns1:Commercial CIT</CarrierName>

<CarrierNumber>10001</CarrierNumber>

<CarrierLocationName>tns1:Riyadh</CarrierLocationName>

<CarrierLocationNumber>100011</CarrierLocationNumber>

<CarrierLocationRouteName>tns1:R1</CarrierLocationRouteName>

<CarrierLocationRouteNumber>R1</CarrierLocationRouteNumber>

<DepositList_Id>0</DepositList_Id>

</Carrier>

-<ContainerList>

<ContainerNumber>903000033102</ContainerNumber>

<ContainerList_Id>0</ContainerList_Id>

<DeclaredAmount>50000</DeclaredAmount>

<DepositList_Id>0</DepositList_Id>

</ContainerList>

</ContainerList>

-<ContainerContentList>

<ContainerContentList_Id>0</ContainerContentList_Id>

<TotalRecordCount>1</TotalRecordCount>

<ContainerList_Id>0</ContainerList_Id>

</ContainerContentList>
-<ContentCategory>

<ISOCurrencyCode>SAR</ISOCurrencyCode>

<InventoryType>Fit Currency</InventoryType>

<InventorySubType>Fit</InventorySubType>

<ContainerContentList_Id>1</ContainerContentList_Id>

</ContentCategory>
-<ContentCategoryItemList>

<ItemFaceValue>5</ItemFaceValue>

<ItemCount>10000</ItemCount>

<DeclaredAmount>50000</DeclaredAmount>

<ContentCategoryItemList_Id>0</ContentCategoryItemList_Id>

<ContainerContentList_Id>0</ContainerContentList_Id>

</ContentCategoryItemList>
-<CategoryItemUnitList>

<InventoryUnitName>Bundle</InventoryUnitName>

<UnitQuantity>10</UnitQuantity>

<UnitAmount>5000</UnitAmount>

<UnitWeight/>

<MeasurementUnit/>

<BeginSerialNumber/>

<Series/>

<EndSerialNumber/>

<ContentCategoryItemList_Id>0</ContentCategoryItemList_Id>

</CategoryItemUnitList>

Expected Output should be something like this

 
-<tns:Header>
<tns1:BankName>SAMA</tns1:BankName>
<tns1:CashCenterName>SAMA Riyadh</tns1:CashCenterName>
</tns:Header>
-<tns:DepositList>
 <tns1:ReferenceNumber>00000001</tns1:ReferenceNumber>
 +<tns1:Carrier>
 +<tns1:Customer>
 -<tns1:ContainerList>
  <tns1:ContainerNumber>903000033102</tns1:ContainerNumber>
    -<tns1:ContainerContentList>
    -<tns1:ContentCategory>
    -<tns1:ContentCategoryItemList>
     <tns1:ItemFaceValue>5.0000</tns1:ItemFaceValue>
     <tns1:ItemCount>10000</tns1:ItemCount>
     <tns1:DeclaredAmount>50000.00</tns1:DeclaredAmount>
        -<tns1:CategoryItemUnitList>
         <tns1:InventoryUnitName>Bundle</tns1:InventoryUnitName>
         <tns1:UnitQuantity>10</tns1:UnitQuantity>
         <tns1:UnitAmount>5000.0</tns1:UnitAmount>
         <tns1:Series/>
        </tns1:CategoryItemUnitList>
    </tns1:ContentCategoryItemList>
    <tns1:TotalRecordCount>1</tns1:TotalRecordCount>
    </tns1:ContainerContentList>

The current xslt is

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl=".....">
 <xsl:output method="xml" indent="yes"/>
 <xsl:strip-space elements="*"/>

 <xsl:template match="/">
  <NewDataSet>
   <xsl:copy-of select="NewDataSet/Header"/>
   <xsl:for-each select="NewDataSet/DepositorList">
    <DepositorList>
     <xsl:variable name="DepositList_Id">
      <xsl:value-of select="DepositList_Id"/>
     </xsl:variable>
     <xsl:copy-of select="*"/>
     <xsl:copy-of select="../Carrier[DepositList_Id=$DepositList_Id]"/>
     <xsl:copy-of select="../Customer[DepositList_Id=$DepositList_Id]"/>
     <xsl:copy-of select="../ContainerList[DepositList_Id=$DepositList_Id]"/>
        
      </DepositorList>
   </xsl:for-each>
  </NewDataSet>
 </xsl:template>
</xsl:stylesheet>

Please suggest

Modify Xslt according to xml

$
0
0

I want to modify xslt file according to output xml

My input xml is

-<NewDataSet><Header><BankName>SAMA</BankName><CashCenterName>SAMA Riyadh</CashCenterName></Header><DepositorList><ReferenceNumber>1</ReferenceNumber><DepositList_Id>0</DepositList_Id><PreparedBy>FZE</PreparedBy><TotalContainerCount>2</TotalContainerCount><ExpectedDate>2018-04-19T09:13:10-05:00</ExpectedDate><DeclaredAmount>150000</DeclaredAmount></DepositorList><Carrier><CarrierName>tns1:Commercial CIT</CarrierName><CarrierNumber>10001</CarrierNumber><CarrierLocationName>tns1:Riyadh</CarrierLocationName><CarrierLocationNumber>100011</CarrierLocationNumber><CarrierLocationRouteName>tns1:R1</CarrierLocationRouteName><CarrierLocationRouteNumber>R1</CarrierLocationRouteNumber><DepositList_Id>0</DepositList_Id>

 </Carrier><Customer><AccountNumber>ISB</AccountNumber><LocationNumber>10065100</LocationNumber><DepositList_Id>0</DepositList_Id></Customer><ContainerList><ContainerNumber>903000033102</ContainerNumber><ContainerList_Id>0</ContainerList_Id><DeclaredAmount>50000</DeclaredAmount><DepositList_Id>0</DepositList_Id></ContainerList><ContainerList><ContainerNumber>903000033103</ContainerNumber><ContainerList_Id>1</ContainerList_Id><DeclaredAmount>100000</DeclaredAmount><DepositList_Id>0</DepositList_Id></ContainerList><ContainerContentList><ContainerContentList_Id>0</ContainerContentList_Id><TotalRecordCount>1</TotalRecordCount><ContainerList_Id>0</ContainerList_Id></ContainerContentList><ContainerContentList><ContainerContentList_Id>1</ContainerContentList_Id><TotalRecordCount>1</TotalRecordCount><ContainerList_Id>1</ContainerList_Id></ContainerContentList><ContentCategory><ISOCurrencyCode>SAR</ISOCurrencyCode><InventoryType>Fit Currency</InventoryType><InventorySubType>Fit</InventorySubType><ContainerContentList_Id>0</ContainerContentList_Id></ContentCategory><ContentCategory><ISOCurrencyCode>SAR</ISOCurrencyCode><InventoryType>Fit Currency</InventoryType><InventorySubType>Fit</InventorySubType><ContainerContentList_Id>1</ContainerContentList_Id></ContentCategory><ContentCategoryItemList><ItemFaceValue>5</ItemFaceValue><ItemCount>10000</ItemCount><DeclaredAmount>50000</DeclaredAmount><ContentCategoryItemList_Id>0</ContentCategoryItemList_Id><ContainerContentList_Id>0</ContainerContentList_Id></ContentCategoryItemList><ContentCategoryItemList><ItemFaceValue>10</ItemFaceValue><ItemCount>10000</ItemCount><DeclaredAmount>100000</DeclaredAmount><ContentCategoryItemList_Id>1</ContentCategoryItemList_Id><ContainerContentList_Id>1</ContainerContentList_Id></ContentCategoryItemList><CategoryItemUnitList><InventoryUnitName>Bundle</InventoryUnitName><UnitQuantity>10</UnitQuantity><UnitAmount>5000</UnitAmount><UnitWeight/><MeasurementUnit/><BeginSerialNumber/><Series/><EndSerialNumber/><ContentCategoryItemList_Id>0</ContentCategoryItemList_Id></CategoryItemUnitList><CategoryItemUnitList><InventoryUnitName>Bundle</InventoryUnitName><UnitQuantity>10</UnitQuantity><UnitAmount>10000</UnitAmount><UnitWeight/><MeasurementUnit/><BeginSerialNumber/><Series/><EndSerialNumber/><ContentCategoryItemList_Id>1</ContentCategoryItemList_Id></CategoryItemUnitList></NewDataSet>


The xslt so far

<?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:output method="xml" indent="yes"/><xsl:strip-space elements="*"/><xsl:template match="/NewDataSet"><NewDataSet><xsl:copy-of select="Header"/><xsl:for-each select="DepositorList"><DepositorList><xsl:variable name="DepositList_Id"><xsl:value-of select="DepositList_Id"/></xsl:variable><xsl:variable name="ContainerList_Id"><xsl:value-of select="../ContainerList[DepositList_Id=$DepositList_Id]/ContainerList_Id"/></xsl:variable><xsl:variable name="ContainerContentList_Id"><xsl:value-of select="../ContainerContentList[ContainerList_Id=$DepositList_Id]/ContainerList_Id/ontainerContentList_Id"/></xsl:variable><xsl:copy-of select="../Carrier[DepositList_Id=$DepositList_Id]"/><xsl:copy-of select="../Customer[DepositList_Id=$DepositList_Id]"/><xsl:copy-of select="*"/><ContainerList><xsl:copy-of select="../ContainerList[DepositList_Id=$DepositList_Id]"/><ContainerContentList>	<xsl:copy-of select="../ContainerContentList[ContainerList_Id=$ContainerList_Id]"/></ContainerContentList>	</ContainerList></DepositorList></xsl:for-each></NewDataSet></xsl:template></xsl:stylesheet>

expected  xml output is

<?xml version='1.0' ?><NewDataSet><Header><BankName>SAMA</BankName><CashCenterName>SAMA Riyadh</CashCenterName></Header><DepositorList><ReferenceNumber>1</ReferenceNumber><DepositList_Id>0</DepositList_Id><PreparedBy>FZE</PreparedBy><TotalContainerCount>2</TotalContainerCount><ExpectedDate>20180419T09:13:1005:00</ExpectedDate><DeclaredAmount>150000.00</DeclaredAmount></DepositorList><Carrier><CarrierName>tns1:Commercial CIT</CarrierName><CarrierNumber>10001</CarrierNumber><CarrierLocationName>tns1:Riyadh</CarrierLocationName><CarrierLocationNumber>100011</CarrierLocationNumber><CarrierLocationRouteName>tns1:R1</CarrierLocationRouteName><CarrierLocationRouteNumber>R1</CarrierLocationRouteNumber><DepositList_Id>0</DepositList_Id></Carrier><Customer><AccountNumber>ISB</AccountNumber><LocationNumber>10065100</LocationNumber><DepositList_Id>0</DepositList_Id></Customer><ContainerList><Container><ContainerNumber>903000033102</ContainerNumber><ContainerList_Id>0</ContainerList_Id><DeclaredAmount>50000.00</DeclaredAmount><DepositList_Id>0</DepositList_Id><ContentCategory><ISOCurrencyCode>SAR</ISOCurrencyCode><InventoryType>Fit Currency</InventoryType><InventorySubType>Fit</InventorySubType></ContentCategory><ContentCategoryItemList><ItemFaceValue>5.0000</ItemFaceValue><ItemCount>10000</ItemCount><DeclaredAmount>50000.00</DeclaredAmount><ContentCategoryItemList_Id>0</ContentCategoryItemList_Id></ContentCategoryItemList><CategoryItemUnitList><InventoryUnitName>Bundle</InventoryUnitName><UnitQuantity>10</UnitQuantity><UnitAmount>5000.0</UnitAmount><UnitWeight/><MeasurementUnit/><BeginSerialNumber/><Series/><EndSerialNumber/></CategoryItemUnitList></Container><Container><ContainerNumber>903000033103</ContainerNumber><ContainerList_Id>1</ContainerList_Id><DeclaredAmount>100000.00</DeclaredAmount><DepositList_Id>0</DepositList_Id><ContentCategory><ISOCurrencyCode>SAR</ISOCurrencyCode><InventoryType>Fit Currency</InventoryType><InventorySubType>Fit</InventorySubType></ContentCategory><ContentCategoryItemList><ItemFaceValue>10.0000</ItemFaceValue><ItemCount>10000</ItemCount><DeclaredAmount>100000.00</DeclaredAmount><ContentCategoryItemList_Id>1</ContentCategoryItemList_Id></ContentCategoryItemList><CategoryItemUnitList><InventoryUnitName>Bundle</InventoryUnitName><UnitQuantity>10</UnitQuantity><UnitAmount>10000.0</UnitAmount><UnitWeight/><MeasurementUnit/><BeginSerialNumber/><Series/><EndSerialNumber/></CategoryItemUnitList></Container></ContainerList></NewDataSet>

Please suggest xslt changes?

The depositor_Id is not a  constant value and there can be n number of deposits in the xml so the attached is only for 1 of them with deposit_Id=0




Limit for tag size?

$
0
0

Is there a limited size for a tag?

I Create an XElement and add several XAttributes. What I considered is, I've got a crash. After redusing the amount of attributes by one, doesn't matter which, it worked well. Thus the crash could not belong to the content of the attribute.

Next I changed one XAttribute to XElement and it worked with a glance. Again, changing a random XAttribute to XElement all works fine.

Is there any limitation for using XAttribute within a XElement?

skip nodes that exceed certain length

$
0
0
I'm reading an xml file. Is there a way to skip certain nodes that have a value that exceeds a certain length?

To remove character from string using xsl and having a hyperlink

$
0
0

Here my testing results so far:

Original:

Results:

But how can i make them as an hyperlink e.g 

<ahref="mailto:{@Users}"><xslvalues-ofselect=@Users/><a/>

My template below

<xsl:call-templatename="tokenize"><xsl:with-paramname="String"select="translate(@Users,'#','')"/></xsl:call-template><xsl:templatename="tokenize"><xsl:paramname="String"/><xsl:paramname="delimiter"select="';'"/><xsl:choose><xsl:whentest="contains($String, $delimiter) and contains(substring-after($String, $delimiter), $delimiter)"><token><xsl:value-ofselect="substring-before($String, $delimiter)"/><xsl:value-ofselect="$delimiter"/></token><!-- recursive call --><xsl:call-templatename="tokenize"><xsl:with-paramname="String"select="substring-after(substring-after($String, $delimiter), $delimiter)"/></xsl:call-template></xsl:when><xsl:otherwise><token><xsl:value-ofselect="$String"/></token></xsl:otherwise></xsl:choose></xsl:template>

Thanks in advance

how to find closing tags in xml file using c# example(i know.we can use schema file)

$
0
0
i have an xml file and sometimes closing tags are missed(i know we can use schema) and just wanna know how to find missing tags using c#( an sample example would be enough)

yogi

unexpected token. The expected token is '='.

$
0
0

Hi I am running below code and I am getting below error,

'ID' is an unexpected token. The expected token is '='. Line 1, position 15.

MY code is below.

 string ss = "<item product ID='124390'>" +

                       "<price>5.95</price>" +
                       "</item>";

            XmlReaderSettings settings = new XmlReaderSettings();
            settings.IgnoreComments = true;
            settings.IgnoreProcessingInstructions = true;
            settings.IgnoreWhitespace = true;
            XmlReader xmlReader = XmlReader.Create(new StringReader(ss), settings);

            while (xmlReader.Read())
            {

            }

I know this error coming with space before ID. How to resolve this issue.

thank you

Amitsp


Amitsp

trying to post to a rest url and get a response in C#.NET

$
0
0

ok here is my code , I get no errors so I am hoping that I am actually receiving a response back , it should be json like this below what I am wondering is how do I now parse it out IE get thecontentId

{"userId": 189,"contentId": 1073,"firstName": "Test","lastName": "Person","preferredName": "Updated preferred name","salutation": "Mr","email": "test.person@test.com","username": "ryan","jobTitle": "Chief Tester","timeZone": "Pacific Standard Time","defaultCulture": "fr","birthday": "Jan 23","phoneNumbers": {"fax": "777-777-7777","mobile": "888-888-8888","tel": "666-666-6666"
    },"images": {"small": "/profileimage/193821700000/1357/50x50/False/0,0,200,200/test.png","medium": "/profileimage/193821700000/1357/250x250/False/0,0,200,200/test.png","large": "/profileimage/193821700000/1357/0x0/False/0,0,200,200/test.png"
    }
}

here is the inline code in an ASPX


<%@ import namespace="System" %>
<%@ import namespace="System" %>
<%@ import namespace="System.Collections.Generic" %>
<%@ import namespace="System.IO" %>
<%@ import namespace="System.Net" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import namespace="Newtonsoft.Json" %>
<%@ Import namespace="Newtonsoft.Json.Linq" %>


<%@ Page Language="C#" Debug="true" %>

<html>
<body>

<%

var PageRequest1 = WebRequest.Create("https://fin.website.com/api/user/username") as HttpWebRequest;
var authToken = Request.Cookies["tfcookie"].Value;
var postData = "username=" + Request.QueryString["samaccountname"];
    postData += "&token=" + authToken;
var data = Encoding.ASCII.GetBytes(postData);
PageRequest1.Method = "POST";

PageRequest1.ContentType = "application/x-www-form-urlencoded";
PageRequest1.ContentLength = data.Length;
using (var stream = PageRequest1.GetRequestStream())
{
    stream.Write(data, 0, data.Length);
}

var response = (HttpWebResponse)PageRequest1.GetResponse();


var reader = new StreamReader(response.GetResponseStream()).ReadToEnd();

%>


</body>
</html>

How do I add one xml document into another xml document?

$
0
0
I am having trouble adding CitationDocumentBatch element that is in this object objXMLInputDoc. I want to add it to this object objXMLCopyOfOriginalInputDoc. It should be added as a child of <soapenv:Body> inside objXMLCopyOfOriginalInputDoc


objXMLInputDoc object contains the following
CitationDocumentBatch schemaVersion="3:5" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">	<CitationDocument>		<Citation>	</CitationDocument></CitationDocumentBatch>



objXMLCopyOfOriginalInputDoc contains the following
<?xml version="1.0" encoding="utf-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing">	<soap:Header xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">	</soap:Header>	<soapenv:Body>	<!--Add CitationDocumentBatch here-->	</soapenv:Body></soapenv:Envelope>



The result I want would be in objXMLCopyOfOriginalInputDoc which after I insert/add CitationDocumentBatch from objXMLInputDoc will look like this
<?xml version="1.0" encoding="utf-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing">	<soap:Header xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">	</soap:Header>	<soapenv:Body>	<CitationDocumentBatch schemaVersion="3:5" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">	<CitationDocument>		<Citation>	</CitationDocument></CitationDocumentBatch>	</soapenv:Body></soapenv:Envelope>



I am trying this in vb.net but I am getting an exception "The node to be inserted is from a different document context."
objXMLCopyOfOriginalInputDoc.DocumentElement.SelectSingleNode("soap:Body", objXMLNameSpaceManager).AppendChild(objXMLInputDoc.SelectSingleNode("//CitationDocumentBatch"))



Can someone help me with this? It might be very easy but I am not able to figure it out.

How do I check the first 3 characters in an element?

$
0
0

I have the node below. I would like to check if the first 3 characters are not equal to 169.

How do I do it using xslt if test? e.g. substring(StatuteCode,1,4)="169") I think is is wrong.

<StatuteCode Word="169142a4">Running</StatuteCode>

my code

<xsl:choose><xsl:when test='(StatuteCode,1,4)="169")'><xsl:value-of select="true()"/></xsl:when><xsl:otherwise><xsl:value-of select="false()"/></xsl:otherwise></xsl:choose>


ignore/remove Namespace URI

$
0
0
I have a xml file with NameSpace on the root node let say xmlns="http://www.mysite.com/"
i.e.
<?xml version="1.0" ?>
<customers xmlns="http://www.mysite.com/">
    <customer job > ....


I am loading this into xmldocument
whaty I want's is to ignore or remove NameSpaceURI from the Xmldocument
It is making some problem in the parsing of the docuement
What Can I do

I am working on .netframework 1.1

When checked using the W3C Validation Service there are some errors. How do I solve these errors? my website is https://www.sebahotnews.org

$
0
0

checked website is https://www.sebahotnews.org

Line 1, Column 16: Attribute “xmlns:b” not allowed here.

TYPE html>↩<html dir='ltr' itemscope='' itemtype='https://schema.org/Blog' xmlns='http://www.w3.org/1999/xhtml' xmlns:b='http://www.google.com/2005/gml/b' xmlns:data='http://www.google.com/2005/gml/data' xmlns:expr='http://www.google.com/2005/gml/expr' xmlns:fb='https://ogp.me/ns/fb#'>↩<head
Line 1, Column 16: Attribute with the local name “xmlns:b” is not serializable as XML 1.0.
TYPE html>↩<html dir='ltr' itemscope='' itemtype='https://schema.org/Blog' xmlns='http://www.w3.org/1999/xhtml' xmlns:b='http://www.google.com/2005/gml/b' xmlns:data='http://www.google.com/2005/gml/data' xmlns:expr='http://www.google.com/2005/gml/expr' xmlns:fb='https://ogp.me/ns/fb#'>↩<head
Line 1, Column 16: Attribute “xmlns:data” not allowed here.
TYPE html>↩<html dir='ltr' itemscope='' itemtype='https://schema.org/Blog' xmlns='http://www.w3.org/1999/xhtml' xmlns:b='http://www.google.com/2005/gml/b' xmlns:data='http://www.google.com/2005/gml/data' xmlns:expr='http://www.google.com/2005/gml/expr' xmlns:fb='https://ogp.me/ns/fb#'>↩<head
Line 1, Column 16: Attribute with the local name “xmlns:data” is not serializable as XML 1.0.
TYPE html>↩<html dir='ltr' itemscope='' itemtype='https://schema.org/Blog' xmlns='http://www.w3.org/1999/xhtml' xmlns:b='http://www.google.com/2005/gml/b' xmlns:data='http://www.google.com/2005/gml/data' xmlns:expr='http://www.google.com/2005/gml/expr' xmlns:fb='https://ogp.me/ns/fb#'>↩<head
Line 1, Column 16: Attribute “xmlns:expr” not allowed here.
TYPE html>↩<html dir='ltr' itemscope='' itemtype='https://schema.org/Blog' xmlns='http://www.w3.org/1999/xhtml' xmlns:b='http://www.google.com/2005/gml/b' xmlns:data='http://www.google.com/2005/gml/data' xmlns:expr='http://www.google.com/2005/gml/expr' xmlns:fb='https://ogp.me/ns/fb#'>↩<head
Line 1, Column 16: Attribute with the local name “xmlns:expr” is not serializable as XML 1.0.
TYPE html>↩<html dir='ltr' itemscope='' itemtype='https://schema.org/Blog' xmlns='http://www.w3.org/1999/xhtml' xmlns:b='http://www.google.com/2005/gml/b' xmlns:data='http://www.google.com/2005/gml/data' xmlns:expr='http://www.google.com/2005/gml/expr' xmlns:fb='https://ogp.me/ns/fb#'>↩<head
Line 1, Column 16: Attribute “xmlns:fb” not allowed here.
TYPE html>↩<html dir='ltr' itemscope='' itemtype='https://schema.org/Blog' xmlns='http://www.w3.org/1999/xhtml' xmlns:b='http://www.google.com/2005/gml/b' xmlns:data='http://www.google.com/2005/gml/data' xmlns:expr='http://www.google.com/2005/gml/expr' xmlns:fb='https://ogp.me/ns/fb#'>↩<head
Line 1, Column 16: Attribute with the local name “xmlns:fb” is not serializable as XML 1.0.
TYPE html>↩<html dir='ltr' itemscope='' itemtype='https://schema.org/Blog' xmlns='http://www.w3.org/1999/xhtml' xmlns:b='http://www.google.com/2005/gml/b' xmlns:data='http://www.google.com/2005/gml/data' xmlns:expr='http://www.google.com/2005/gml/expr' xmlns:fb='https://ogp.me/ns/fb#'>↩<head

3D effects in tiles in xaml

$
0
0

I am using MahApps.metro a third party library for creating tiles in wpf xaml but I need these tiles to give a 3D effect.

Can anyone provide me piece of code for 3D effects on these tiles.

My code is:

<controls:Tile TiltFactor="2" Background="Transparent" Foreground="White" Grid.Row="1" Grid.Column="1" Width="{Binding TileWidth,UpdateSourceTrigger=PropertyChanged}" Height="{Binding TileHeight,UpdateSourceTrigger=PropertyChanged}" controls:ControlsHelper.MouseOverBorderBrush="White" ToolTip="Home" Command="{Binding RestartCommand}" BorderBrush="#FF0080FF" BorderThickness="1">

                   

                   <Grid Width="{Binding TileWidth,UpdateSourceTrigger=PropertyChanged}" Height="{Binding TileHeight,UpdateSourceTrigger=PropertyChanged}">

                       <Grid.RowDefinitions>

                           <RowDefinition/>

                           <RowDefinition Height="20"/>

                       </Grid.RowDefinitions>

                       <Grid Grid.Row="0" Width="{Binding IconWidth,UpdateSourceTrigger=PropertyChanged}" Height="{Binding IconHeight,UpdateSourceTrigger=PropertyChanged}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">

                           <Grid.Background>

                               <ImageBrush ImageSource="../Images/home.png"/>

                           </Grid.Background>

                       </Grid>

                       <TextBlock Grid.Row="1" HorizontalAlignment="Center" VerticalAlignment="Bottom" FontSize="16" Foreground="#FF0080FF" FontWeight="Bold" Margin="0,0,0,5"><Run Text="Home"/></TextBlock>

                       

                   </Grid>

               </controls:Tile>

Sorting xml nodes in c#

$
0
0

How to sort the below xml based on DOB

<recentData>
  <info>
    <Name>Vivek</Name>
    <DOB>20-07-2018</DOB>
    <Salary>6,458</Salary>
  </info>
  <info>
    <Name>Daniel</Name>
    <DOB>02-07-2018</DOB>
    <Salary>6,458</Salary>
  </info>
  <info>
    <Name>Mahat</Name>
    <DOB>15-07-2018</DOB>
    <Salary>6,458</Salary>
  </info>
 </recentData>

like this

 <recentData>
   <info>
    <Name>Daniel</Name>
    <DOB>02-07-2018</DOB>
    <Salary>6,458</Salary>
  </info>
    <info>
    <Name>Mahat</Name>
    <DOB>15-07-2018</DOB>
    <Salary>6,458</Salary>
  </info>
  <info>
    <Name>Vivek</Name>
    <DOB>20-07-2018</DOB>
    <Salary>6,458</Salary>
  </info>
 </recentData>

Need help creating component and sending post

$
0
0

We host two sites on a typical Windows Server 2016 shared-hosting provider. We use ASP Classic writing in javascript. We post credit card transactions to Authorize.net using the MSXML2.ServerXMLHTTP.6.0 object. It works perfectly, except that in five out of ten times (about half the time), when the MSXML2.ServerXMLHTTP.6.0 object sends the post, it times out with this error:

msxml6.dllerror '80072ee2'

The operation timed out 

/admin_TLS_test.asp, line 35 (Line 35 is objRequest.send();)

We created a test post to https://www.howsmyssl.com/a/check and get the same result, so the timeout is being caused by our server trying to send the post and not authorize.net.

We have tested creating the object three different ways:

objRequest = Server.CreateObject("MSXML2.ServerXMLHTTP.6.0")

objRequest = new ActiveXObject("MSXML2.ServerXMLHTTP.6.0")

objRequest = Server.CreateObject("WinHTTP.WinHTTPRequest.5.1")

Then we set up the post and send:

objRequest.open("GET", post_url, false);
objRequest.send();

We have researched this thoroughly, but cannot find an explanation of why it may be timing out half the time (the send() line is the line that times out) and we cannot find out what the difference is between "Server.CreateObject" and "new ActiveXObject" but both work fine when it doesn't time out.

Any help with these two issues would be helpful

Thank you.


Sorting xml nodes using elements in c#

$
0
0

Hi, I have the below XML element that need to sorted based on date of birth

            <Info>
<EmployeeDetail>
                <field fieldKey="Employee Name" name="EMPLOYEE NAME" value="Chirs"/>
                <field fieldKey="date of birth" name="DATE OF BIRTH" value="02-07-1990"/>
                <field fieldKey="Salary" name="SALARY" value="6,458"/>
              </EmployeeDetail>
              <EmployeeDetail>
                <field fieldKey="Employee Name" name="EMPLOYEE NAME" value="Mothie"/>
                <field fieldKey="date of birth" name="DATE OF BIRTH" value="13-08-2000"/>
                <field fieldKey="Salary" name="SALARY" value="6,458"/>
              </EmployeeDetail>
  <EmployeeDetail>
                <field fieldKey="Employee Name" name="EMPLOYEE NAME" value="Manie"/>
                <field fieldKey="date of birth" name="DATE OF BIRTH" value="03-07-1990"/>
                <field fieldKey="Salary" name="SALARY" value="6,458"/>
              </EmployeeDetail>
</Info>


Output should be like this 
"<Info>
  <EmployeeDetail>
                <field fieldKey="Employee Name" name="EMPLOYEE NAME" value="Mothie"/>
                <field fieldKey="date of birth" name="DATE OF BIRTH" value="13-08-2000"/>
                <field fieldKey="Salary" name="SALARY" value="6,458"/>
              </EmployeeDetail>
              <EmployeeDetail>
                <field fieldKey="Employee Name" name="EMPLOYEE NAME" value="Manie"/>
                <field fieldKey="date of birth" name="DATE OF BIRTH" value="03-07-1990"/>
                <field fieldKey="Salary" name="SALARY" value="6,458"/>
              </EmployeeDetail>
  <EmployeeDetail>
                <field fieldKey="Employee Name" name="EMPLOYEE NAME" value="Chirs"/>
                <field fieldKey="date of birth" name="DATE OF BIRTH" value="02-07-1990"/>
                <field fieldKey="Salary" name="SALARY" value="6,458"/>
              </EmployeeDetail>
</Info>"

Viewing all 935 articles
Browse latest View live