I am having xml response like below
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<CreateMeetMeOrWebMeetingResults
xmlns:ns2="coss-ws-common">
<transactionId>z8kflt5fi2x28vd51</transactionId>
<status>OK</status>
<meetme id="178635601">
<billingCode>MR5942965</billingCode>
<confirmationId>Q-1GFR347H6I</confirmationId>
<serviceId>1021</serviceId>
<serviceName>BT MeetMe</serviceName>
<timezone>America/New_York</timezone>
<topic>Danny Chung</topic>
<chairpasscode>34132738</chairpasscode>
<participantpasscode>84781442</participantpasscode>
<dialInNumber>
<phoneType>PSTN</phoneType>
<formattedNumber>0203 463 9676</formattedNumber>
<displayName>Direct: 0203 463 9676</displayName>
<rawNumber>02034639676</rawNumber>
</dialInNumber>
<createDate>2014-11-25T09:34:33.168Z</createDate>
<createdByApplicationId>1120</createdByApplicationId>
<bridgeId>892</bridgeId>
<recurringFlag>false</recurringFlag>
<globalAccessFeature locked="false" enabled="true">
<url>Please contact help desk</url>
</globalAccessFeature>
<meetingType>MEETME</meetingType>
<serviceType>MEETME</serviceType>
<pendingBlackoutDateApproval>false</pendingBlackoutDateApproval>
<chairpersonRecord locked="false" enabled="true"/>
</meetme>
</CreateMeetMeOrWebMeetingResults>
I am trying to convert it into xml by doc.LoadXml(response) and its giving error for invalid data at root level.
if somebody can help to solve the issue
If that is your complete xml, you missed a closing tag:
</CreateMeetMeOrWebMeetingResults>
Try adding it at the bottom of your xml
Looking at your indentation, could be that your xml starts with a whitespace. This could be another reason
You don't seem to have a root element for your xml. This works for me.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<root>
<CreateMeetMeOrWebMeetingResults xmlns:ns2="coss-ws-common"/>
<transactionId>z8kflt5fi2x28vd51</transactionId>
<status>OK</status>
<meetme id="178635601">
<billingCode>MR5942965</billingCode>
<confirmationId>Q-1GFR347H6I</confirmationId>
<serviceId>1021</serviceId>
<serviceName>BT MeetMe</serviceName>
<timezone>America/New_York</timezone>
<topic>Danny Chung</topic>
<chairpasscode>34132738</chairpasscode>
<participantpasscode>84781442</participantpasscode>
<dialInNumber>
<phoneType>PSTN</phoneType>
<formattedNumber>0203 463 9676</formattedNumber>
<displayName>Direct: 0203 463 9676</displayName>
<rawNumber>02034639676</rawNumber>
</dialInNumber>
<createDate>2014-11-25T09:34:33.168Z</createDate>
<createdByApplicationId>1120</createdByApplicationId>
<bridgeId>892</bridgeId>
<recurringFlag>false</recurringFlag>
<globalAccessFeature locked="false" enabled="true">
<url>Please contact help desk</url>
</globalAccessFeature>
<meetingType>MEETME</meetingType>
<serviceType>MEETME</serviceType>
<pendingBlackoutDateApproval>false</pendingBlackoutDateApproval>
<chairpersonRecord locked="false" enabled="true"/>
</meetme>
</root>
Related
i am facing ERR.SWS.CLIENT.VALIDATION_FAILED exception in my code
my Request to Sabre
<?xml version="1.0" encoding="utf-16"?>
<TravelItineraryReadRQ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" Version="3.9.0">
<MessagingDetails xmlns="http://services.sabre.com/res/tir/v3_10">
<SubjectAreas>
<SubjectArea>DEFAULT</SubjectArea>
</SubjectAreas>
</MessagingDetails>
<UniqueID ID="XXXXXX this is changed" xmlns="http://services.sabre.com/res/tir/v3_10" />
<ReturnOptions xmlns="http://services.sabre.com/res/tir/v3_10" />
</TravelItineraryReadRQ>
Kindly Help me in this exception
The one below works for me:
<TravelItineraryReadRQ Version="3.9.0" TimeStamp="2012-09-19T10:00:00-06:00"
xmlns="http://webservices.sabre.com/sabreXML/2011/10">
<MessagingDetails>
<SubjectAreas>
<SubjectArea>FULL</SubjectArea>
</SubjectAreas>
</MessagingDetails>
<UniqueID ID="XXXXXX"/>
<ReturnOptions UnmaskCreditCard="false"/>
</TravelItineraryReadRQ>
Did you also set the headers correctly?
I have a config file I'm transforming:
<?xml version="1.0" encoding="utf-8"?>
<TopNode>
<Sub>
<subnode>aaaa</subnode>
<othernode>sdfsfsdfsd</othernode>
</Sub>
<Sub>
<subnode>aaaa</subnode>
<othernode>iiiiiii</othernode>
</Sub>
<Sub>
<subnode>aaaa</subnode>
<othernode>blahblahblahblabhlahb</othernode>
</Sub>
<Sub>
<subnode>aaaa</subnode>
<othernode>sdfsdfseeferererer</othernode>
</Sub>
</TopNode>
I have this transform:
<?xml version="1.0" encoding="utf-8" ?>
<TopNode xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<Sub>
<subnode xdt:Transform="Replace">replaceallwiththis</subnode>
</Sub>
</TopNode>
It only replaces the first subnode match. How do I get it to replace all?
I also try like this but no work:
<subnode xdt:Locator="Condition(.)" xdt:Transform="Replace">replaceallwiththis</subnode>
I also trya dis but she a no work (only replaces first match):
<subnode xdt:Locator="XPath(//TopNode/Sub[subnode='aaaa']/subnode)" xdt:Transform="Replace">zzzzzzzzzzzzzzzzzzz</subnode>
I have this following xsd file. I try to generate class using vs command line like:
command line word = xsd test.xsd /c
"Data at the root level is invalid. Line2, position1.". I am not sure why I having this error. Please advise.
<?xml version="1.0" ?>
- <ResultSet>
- <DataRow>
<Mailing>CCACCL0030</Mailing>
<MailingDesc>'other response' chelsea CA</MailingDesc>
<Notes />
<Direction>O</Direction>
<HistoryOnly>N</HistoryOnly>
</DataRow>
- <DataRow>
<Mailing>VOUCHER20</Mailing>
<MailingDesc>£20 T&M Voucher</MailingDesc>
<Notes />
<Direction>O</Direction>
<HistoryOnly>N</HistoryOnly>
</DataRow>
-
</ResultSet>
To generate code:
Edit the example file so that the & character is encoded. Specifically, swap it for &
Rename the file to test.xml
Run xsd.exe test.xml to generate a schema e.g. test.xsd
Run xsd.exe /c test.xsd to generate classes from the schema
EDIT: This worked fine for me. Here's the contents of my test.xml:
<?xml version="1.0" ?>
<ResultSet>
<DataRow>
<Mailing>CCACCL0030</Mailing>
<MailingDesc>'other response' chelsea CA</MailingDesc>
<Notes />
<Direction>O</Direction>
<HistoryOnly>N</HistoryOnly>
</DataRow>
<DataRow>
<Mailing>VOUCHER20</Mailing>
<MailingDesc>£20 T&M Voucher</MailingDesc>
<Notes />
<Direction>O</Direction>
<HistoryOnly>N</HistoryOnly>
</DataRow>
</ResultSet>
In C#, Asp.Net, I am trying to return the Error node inside of BISearchResponse:
I am able to get the GetWireResult node returned in an XMLNode.
How do I get to the Error node?
<?xml version="1.0" encoding="utf-8" ?>
- <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
- <soap:Body>
- <GetWireResponse xmlns="http://OpenSolutions.com/">
<GetWireResult><?xml version="1.0"?>
<BISearchResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Error xmlns="https://bixg.choicepoint.com/webservices/3.0">
<Message>BI System: Failed to Login</Message>
<Code>536870917</Code>
</Error>
</BISearchResponse>
</GetWireResult>
</GetWireResponse>
</soap:Body>
</soap:Envelope>
My code:
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(result);
XmlNamespaceManager nsmgr = new XmlNamespaceManager(xmlDoc.NameTable);
nsmgr.AddNamespace("soap", "http://schemas.xmlsoap.org/soap/envelope/");
nsmgr.AddNamespace("ab", "http://OpenSolutions.com/");
nsmgr.AddNamespace("bg", " https://bixg.choicepoint.com/webservices/3.0");
nsmgr.AddNamespace("xsd", "http://www.w3.org/2001/XMLSchema");
nsmgr.AddNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
XmlNode xmlnode = xmlDoc.DocumentElement.SelectSingleNode("/soap:Envelope/soap:Body/ab:GetWireResponse", nsmgr);
This works to here.
.
I am adding the xml here, but it is only visible in edit mode.
<?xml version="1.0" encoding="utf-8" ?>
- <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
- <soap:Body>
- <GetWireResponse xmlns="http://OpenSolutions.com/">
<GetWireResult><?xml version="1.0"?> <BISearchResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <Error xmlns="https://bixg.choicepoint.com/webservices/3.0"> <Message>BI System: Failed to Login</Message> <Code>536870917</Code> </Error> </BISearchResponse></GetWireResult>
</GetWireResponse>
</soap:Body>
</soap:Envelope>
In debug mode, when you copy this XML, try choose another debug visualizer, e.g. "Text visualizer". You can select it clicking the magnifying glass icon in datatip.
I think your XML looks like:
<?xml version="1.0" encoding="utf-8" ?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<GetWireResponse xmlns="http://OpenSolutions.com/">
<GetWireResult>
<?xml version="1.0"?>
<BISearchResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Error xmlns="https://bixg.choicepoint.com/webservices/3.0">
<Message>BI System: Failed to Login</Message>
<Code>536870917</Code>
</Error>
</BISearchResponse>
</GetWireResult>
</GetWireResponse>
</soap:Body>
</soap:Envelope>
or
<?xml version="1.0" encoding="utf-8" ?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<GetWireResponse xmlns="http://OpenSolutions.com/">
<GetWireResult>
<![CDATA[
<?xml version="1.0"?>
<BISearchResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Error xmlns="https://bixg.choicepoint.com/webservices/3.0">
<Message>BI System: Failed to Login</Message>
<Code>536870917</Code>
</Error>
</BISearchResponse>
]]>
</GetWireResult>
</GetWireResponse>
</soap:Body>
</soap:Envelope>
No matter. So you can select GetWireResult using following XPath:
/soap:Envelope/soap:Body/ab:GetWireResponse/ab:GetWireResult
and then load it content in new XML document and get desired response.
You're almost there. Extend your XPath
"/soap:Envelope/soap:Body/ab:GetWireResponse"
to
"/soap:Envelope/soap:Body/ab:GetWireResponse/ab:GetWireResult/ab:BISearchResponse/bg:Error"
However that extra XML prologue stuck in there in the middle, <?xml version="1.0"?>, makes the XML not well-formed. I'm surprised it can be processed at all. I would think the C# API should throw an exception on xmlDoc.LoadXml(result).
Another approach, seeing as the above does not return anything for you, would be to use your C# code to explore the structure of the XML document and print out the children of each node. E.g. if you are getting a node for "/soap:Envelope/soap:Body/ab:GetWireResponse" but not for "/soap:Envelope/soap:Body/ab:GetWireResponse/ab:GetWireResult", does ab:GetWireResponse have what text node children, and if so, what are their values (contents)? That should give insight into why the XPath is not working.
If there's a block of unparsed (i.e. escaped) XML in there, you could either copy it out and parse it as XML like you said, or just search for the pattern you need using a regexp... depending on the complexity.
I am currently using DOM to navigate xml in my C# project. However, some XML that i've come across lately is a bit different.
whereas usually I have:
<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<entry>
<author>
<name>Me =)</name>
</author>
<content>
<somefield1>
<Subfield>subfield data</subfield>
</somefield>
</content>
</entry>
</feed>
and can navigate using foreach entry as entry, selectsinglenode(/content/somefield1/subfield), innertext to get the data from the subfield for each entry, the new XML looks like this:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<atom:feed xmlns:atom="http://www.w3.org/2005/Atom">
<atom:entry>
<atom:author>
<name>Me =)</name>
</atom:author>
<atom:content>
<somefield1>
<Subfield>subfield data</subfield>
</somefield>
</atom:content>
</atom:entry>
</atom:feed>
selectsinglenode(/atom:content/somefield1/subfield) is definitely not going to work...any suggestions?
atom: is just the namespace, and possibly you might just ignore it. If it still not works, you may have to use:
XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
nsmgr.AddNamespace("atom", "http://www.w3.org/2005/Atom");
selectsinglenode("atom:content/somefield1/subfield", nsmgr);
Which is documented here